diff options
Diffstat (limited to 'external_libs/python/pyzmq-14.7.0/examples/bench/benchmark.py')
-rw-r--r-- | external_libs/python/pyzmq-14.7.0/examples/bench/benchmark.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/external_libs/python/pyzmq-14.7.0/examples/bench/benchmark.py b/external_libs/python/pyzmq-14.7.0/examples/bench/benchmark.py new file mode 100644 index 00000000..c379af9a --- /dev/null +++ b/external_libs/python/pyzmq-14.7.0/examples/bench/benchmark.py @@ -0,0 +1,25 @@ +from timeit import default_timer as timer + +def benchmark(f, size, reps): + msg = size*'0' + t1 = timer() + for i in range(reps): + msg2 = f(msg) + assert msg == msg2 + t2 = timer() + diff = (t2-t1) + latency = diff/reps + return latency*1000000 + +kB = [1000*2**n for n in range(10)] +MB = [1000000*2**n for n in range(8)] +sizes = [1] + kB + MB + +def benchmark_set(f, sizes, reps): + latencies = [] + for size, rep in zip(sizes, reps): + print "Running benchmark with %r reps of %r bytes" % (rep, size) + lat = benchmark(f, size, rep) + latencies.append(lat) + return sizes, latencies + |