Skip to content

Commit 78a0354

Browse files
committed
make benchmark harness work again with jython 2.7
1 parent e53a9d5 commit 78a0354

File tree

1 file changed

+9
-4
lines changed
  • graalpython/com.oracle.graal.python.benchmarks/python

1 file changed

+9
-4
lines changed

graalpython/com.oracle.graal.python.benchmarks/python/harness.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@
4747
import sys
4848
import types
4949

50-
GRAALPYTHON = sys.implementation.name == "graalpython"
50+
try:
51+
import statistics
52+
except ImportError:
53+
statistics = None
54+
55+
# for compatibility with Jython 2.7
56+
GRAALPYTHON = getattr(getattr(sys, "implementation", None), "name", None) == "graalpython"
5157

5258
# Try to use the timer with best accuracy. Unfortunately, 'monotonic_ns' is not available everywhere.
5359
if GRAALPYTHON:
@@ -57,7 +63,7 @@
5763
else:
5864
monotonic_best_accuracy = time
5965
UNITS_PER_SECOND = 1.0
60-
66+
6167
_HRULE = '-'.join(['' for i in range(80)])
6268

6369
#: this function is used to pre-process the arguments as expected by the __benchmark__ and __setup__ entry points
@@ -329,8 +335,7 @@ def run(self):
329335
# a bit of fuzzy logic to avoid timing out on configurations
330336
# that are slow, without having to rework our logic for getting
331337
# default iterations
332-
if os.environ.get("CI") and iteration >= 4 and duration > 20:
333-
import statistics
338+
if statistics and os.environ.get("CI") and iteration >= 4 and duration > 20:
334339
v = durations[-4:]
335340
if statistics.stdev(v) / min(v) < 0.03:
336341
# with less than 3 percent variance across ~20s

0 commit comments

Comments
 (0)