4 examples of 'python benchmark timer' in Python

Every line of 'python benchmark timer' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
73def benchmark():
74 """Run the benchmark and print benchmark results."""
75 setup = "from scipy.stats import arcsine; from random import random;"
76 stmt = "y = arcsine.cdf(random(), 10.56789, 55.54321)"
77
78 t = timeit.Timer(stmt, setup=setup)
79
80 print_version()
81
82 for i in xrange(REPEATS):
83 print("# python::" + NAME)
84 elapsed = t.timeit(number=ITERATIONS)
85 print_results(elapsed)
86 print("ok " + str(i+1) + " benchmark finished")
87
88 print_summary(REPEATS, REPEATS)
73def benchmark():
74 """Run the benchmark and print benchmark results."""
75 setup = "from math import exp; from random import random;"
76 stmt = "y = exp(100.0*random() - 50.0)"
77
78 t = timeit.Timer(stmt, setup=setup)
79
80 print_version()
81
82 for i in xrange(REPEATS):
83 print("# python::" + NAME)
84 elapsed = t.timeit(number=ITERATIONS)
85 print_results(elapsed)
86 print("ok " + str(i+1) + " benchmark finished")
87
88 print_summary(REPEATS, REPEATS)
32def bench(func):
33 """Print the runtime of the decorated function"""
34 @functools.wraps(func)
35 def wrapper_timer(*args, **kwargs):
36 nb_iterations = kwargs.get('nb_iterations', DEFAULT_ITERATIONS)
37
38 total_time = 0.0
39 for i in range(nb_iterations):
40 start_time = timer()
41 value = func(*args, **kwargs)
42 end_time = timer()
43 total_time += end_time - start_time
44
45 total_time /= nb_iterations
46 print(f"Finished in {total_time*1e6:.2f} ns over {nb_iterations} runs")
47 return value
48 return wrapper_timer
6def test_timer():
7 '''Testing (Adaptive)ETA when the value doesn't actually change'''
8 widgets = [
9 progressbar.Timer(),
10 ]
11 p = progressbar.ProgressBar(max_value=2, widgets=widgets,
12 poll_interval=0.0001)
13
14 p.start()
15 p.update()
16 p.update(1)
17 p._needs_update()
18 time.sleep(0.001)
19 p.update(1)
20 p.finish()

Related snippets