Skip to content

Commit db5a6ae

Browse files
committed
issue #158: Replace python-3.4 only statistics module with hand-made
stats-funcs.
1 parent 7225b76 commit db5a6ae

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

jsonschema/tests/test_benchmarks.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import statistics
1+
from math import sqrt
22
from textwrap import dedent
33
import time
44

@@ -7,6 +7,17 @@
77
Draft3Validator, Draft4Validator, RefResolver,
88
)
99

10+
try:
11+
from statistics import (mean, stdev)
12+
except ImportError:
13+
def mean(arr):
14+
return sum(arr) / len(arr)
15+
def stdev(arr):
16+
m = mean(arr)
17+
return sqrt(sum(((a - m) ** 2) for a in arr)) / len(arr)
18+
19+
20+
1021

1122
class TestBenchmarks(unittest.TestCase):
1223

@@ -33,7 +44,7 @@ def print_results(self, runs, stats):
3344
print("%i runs in %.2f sec\n"
3445
"\tms/run: mean(%.2f), std(%.2f), MIN(%.2f), MAX(%.2f)" %
3546
(runs, total_duration,
36-
statistics.mean(stats), statistics.stdev(stats),
47+
mean(stats), stdev(stats),
3748
min(stats), max(stats)
3849
))
3950

0 commit comments

Comments
 (0)