2016-10-30 16:15:30 +00:00
|
|
|
# Write the benchmarking functions here.
|
|
|
|
# See "Writing benchmarks" in the asv docs for more information.
|
2016-10-31 00:26:10 +00:00
|
|
|
from __future__ import division
|
2016-10-30 16:15:30 +00:00
|
|
|
|
|
|
|
|
2016-10-31 00:26:10 +00:00
|
|
|
class FractionalOverheadSuite:
|
2016-10-30 16:15:30 +00:00
|
|
|
"""
|
|
|
|
An example benchmark that times the performance of various kinds
|
|
|
|
of iterating over dictionaries in Python.
|
|
|
|
"""
|
|
|
|
def setup(self):
|
2016-10-31 00:26:10 +00:00
|
|
|
try:
|
|
|
|
from time import process_time
|
|
|
|
self.time = process_time
|
|
|
|
except ImportError:
|
|
|
|
from time import clock
|
|
|
|
self.time = clock
|
2016-10-30 16:15:30 +00:00
|
|
|
from tqdm import tqdm
|
|
|
|
self.tqdm = tqdm
|
|
|
|
try:
|
|
|
|
self.iterable = xrange(int(6e6))
|
2016-10-31 01:53:14 +00:00
|
|
|
except NameError:
|
2016-10-30 16:15:30 +00:00
|
|
|
self.iterable = range(int(6e6))
|
|
|
|
|
2016-10-31 00:26:10 +00:00
|
|
|
t0 = self.time()
|
|
|
|
[0 for _ in self.iterable]
|
|
|
|
t1 = self.time()
|
|
|
|
self.t = t1 - t0
|
2016-10-30 16:15:30 +00:00
|
|
|
|
2016-10-31 00:26:10 +00:00
|
|
|
def track_tqdm(self):
|
|
|
|
t0 = self.time()
|
|
|
|
[0 for _ in self.tqdm(self.iterable)]
|
|
|
|
t1 = self.time()
|
2016-10-31 01:53:14 +00:00
|
|
|
return (t1 - t0 - self.t) / self.t
|
|
|
|
|
|
|
|
def track_optimsed(self):
|
|
|
|
t0 = self.time()
|
|
|
|
[0 for _ in self.tqdm(self.iterable,
|
|
|
|
miniters=6e5, smoothing=0)]
|
|
|
|
# TODO: miniters=None, mininterval=0.1, smoothing=0)]
|
|
|
|
t1 = self.time()
|
|
|
|
return (t1 - t0 - self.t) / self.t
|