diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-11-19 08:57:43 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-11-19 08:57:43 -0500 |
commit | 845bd546d42afe4e701fc05ad4b581c795b5370c (patch) | |
tree | 45b61ccf1af7431ef3d43f9f1c9e3b4351a1eeb9 /lab/bug397.py | |
parent | b542928d589edadcfa960c5c5bf0fa97b0cf07f8 (diff) | |
download | python-coveragepy-git-845bd546d42afe4e701fc05ad4b581c795b5370c.tar.gz |
This file was a performance test of sorts
--HG--
rename : lab/bug397.py => perf/bug397.py
Diffstat (limited to 'lab/bug397.py')
-rw-r--r-- | lab/bug397.py | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/lab/bug397.py b/lab/bug397.py deleted file mode 100644 index 4d72e908..00000000 --- a/lab/bug397.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python -""" -Run this file two ways under coverage and see that the times are the same: - - $ coverage run lab/bug397.py slow - Runtime per example: 130.96 +/- 3.70 us - $ coverage run lab/bug397.py fast - Runtime per example: 131.34 +/- 4.48 us - -Written by David MacIver as part of -https://bitbucket.org/ned/coveragepy/issues/397/stopping-and-resuming-coverage-with - -""" -from __future__ import print_function - -import sys -import random -import time -import math - -if sys.argv[1] == "slow": - sys.settrace(sys.gettrace()) - -random.seed(1) - - -def hash_str(s): - h = 0 - for c in s: - h = (h * 31 + ord(c)) & (2 ** 64 - 1) - return h - -data = [ - hex(random.getrandbits(1024)) for _ in range(500) -] - -N_SAMPLES = 100 - - -def mean(xs): - xs = list(xs) - return sum(xs) / len(xs) - - -def sd(xs): - return math.sqrt(mean(x ** 2 for x in xs) - mean(xs) ** 2) - - -if __name__ == '__main__': - timing = [] - for _ in range(N_SAMPLES): - start = time.time() - for d in data: - hash_str(d) - timing.append(1000000 * (time.time() - start) / len(data)) - print("Runtime per example:", "%.2f +/- %.2f us" % (mean(timing), sd(timing))) |