diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2016-06-10 13:56:58 -0400 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2016-06-10 13:56:58 -0400 |
| commit | b03ee9e4e41c6d0f982a0b04f0cd4fb8a13c04d2 (patch) | |
| tree | b4b3f00cade0b0370d81868d83d95b501d00aefc /admin | |
| parent | dbf60ebae71568df71476910f5d387b3109f03b3 (diff) | |
| download | passlib-b03ee9e4e41c6d0f982a0b04f0cd4fb8a13c04d2.tar.gz | |
passlib.tests.test_totp: use proper timing tool for runtime measurement,
prevents some spurious test failures when under erratic system load
Diffstat (limited to 'admin')
| -rw-r--r-- | admin/benchmarks.py | 20 |
1 files changed, 2 insertions, 18 deletions
diff --git a/admin/benchmarks.py b/admin/benchmarks.py index 5ba52d0..edf9427 100644 --- a/admin/benchmarks.py +++ b/admin/benchmarks.py @@ -25,6 +25,7 @@ except ImportError: PasslibConfigWarning = None import passlib.utils.handlers as uh from passlib.utils.compat import u, print_, unicode +from passlib.tests.utils import time_call # local #============================================================================= @@ -69,24 +70,7 @@ class benchmark: else: raise ValueError("invalid mode: %r" % (mode,)) - @staticmethod - def measure(func, setup=None, maxtime=1, bestof=3): - """timeit() wrapper which tries to get as accurate a measurement as - possible w/in maxtime seconds. - - :returns: - ``(avg_seconds_per_call, log10_number_of_repetitions)`` - """ - from timeit import Timer - from math import log - timer = Timer(func, setup=setup or '') - number = 1 - while True: - delta = min(timer.repeat(bestof, number)) - maxtime -= delta*bestof - if maxtime < 0: - return delta/number, int(log(number, 10)) - number *= 10 + measure = staticmethod(time_call) @staticmethod def pptime(secs, precision=3): |
