bachelor_thesis/performance/measure_circuit.py

31 lines
747 B
Python
Raw Normal View History

2020-02-01 09:26:06 +00:00
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