import timeit from collections import deque import numpy as np def measure_execution_time(circuit, state, repeat=100, **kwargs): results = deque() for _ in range(repeat): s = state.deepcopy() start = timeit.default_timer() result = circuit * s stop = timeit.default_timer() results.append(stop - start) return min(results) def execution_statistics(circuits, state, scale=1, **kwargs): results = deque() for circuit in circuits: results.append(measure_execution_time(circuit, state, **kwargs)) results = np.array(results, dtype=np.double) results /= scale N = len(results) avg = np.average(results) std_dev = np.std(results) return N, avg, std_dev