Skip to content

Apache DataFusion SQL Query Engine

ARROW-11944: [Developer] Fix archery's comparison of cached benchmark runs

Benjamin Kietzman06927ada5dd9
diff --git a/dev/archery/archery/benchmark/runner.py b/dev/archery/archery/benchmark/runner.py
index f98fb664f9..5718bcaf10 100644
--- a/dev/archery/archery/benchmark/runner.py
+++ b/dev/archery/archery/benchmark/runner.py
@@ -120,11 +120,14 @@ class StaticBenchmarkRunner(BenchmarkRunner):
@staticmethod
def from_json(path_or_str, **kwargs):
- # breaks recursive imports
- from ..utils.codec import BenchmarkRunnerCodec
- path_or_str, json_load = (open(path_or_str), json.load) \
- if os.path.isfile(path_or_str) else (path_or_str, json.loads)
- return BenchmarkRunnerCodec.decode(json_load(path_or_str), **kwargs)
+ # .codec imported here to break recursive imports
+ from .codec import BenchmarkRunnerCodec
+ if os.path.isfile(path_or_str):
+ with open(path_or_str) as f:
+ loaded = json.load(f)
+ else:
+ loaded = json.loads(path_or_str)
+ return BenchmarkRunnerCodec.decode(loaded, **kwargs)
def __repr__(self):
return "BenchmarkRunner[suites={}]".format(list(self.suites))
diff --git a/dev/archery/archery/tests/test_benchmarks.py b/dev/archery/archery/tests/test_benchmarks.py
index b763ea3c86..52be8136c5 100644
--- a/dev/archery/archery/tests/test_benchmarks.py
+++ b/dev/archery/archery/tests/test_benchmarks.py
@@ -19,10 +19,13 @@ import json
from archery.benchmark.codec import JsonEncoder
from archery.benchmark.core import Benchmark, median
-from archery.benchmark.compare import BenchmarkComparator
+from archery.benchmark.compare import (
+ BenchmarkComparator, RunnerComparator
+)
from archery.benchmark.google import (
GoogleBenchmark, GoogleBenchmarkObservation
)
+from archery.benchmark.runner import StaticBenchmarkRunner
def test_benchmark_comparator():
@@ -49,6 +52,54 @@ def test_benchmark_comparator():
).regression
+def test_static_runner_from_json():
+ # full output of `archery benchmark run`
+ archery_result = {
+ "suites": [
+ {
+ "name": "arrow-value-parsing-benchmark",
+ "benchmarks": [
+ {
+ "name": "FloatParsing<DoubleType>",
+ "unit": "items_per_second",
+ "less_is_better": False,
+ "values": [
+ 109941112.87296811
+ ],
+ "time_unit": "ns",
+ "times": [
+ 9095.800104330105
+ ]
+ },
+ {
+ "name": "FloatParsing<FloatType>",
+ "unit": "items_per_second",
+ "less_is_better": False,
+ "values": [
+ 105982641.9337845
+ ],
+ "time_unit": "ns",
+ "times": [
+ 9435.567922160235
+ ]
+ }
+ ]
+ }
+ ]
+ }
+
+ contender = StaticBenchmarkRunner.from_json(json.dumps(archery_result))
+
+ # introduce artificial regression:
+ archery_result['suites'][0]['benchmarks'][0]['values'][0] *= 2
+ baseline = StaticBenchmarkRunner.from_json(json.dumps(archery_result))
+
+ artificial_reg, normal = RunnerComparator(contender, baseline).comparisons
+
+ assert artificial_reg.regression
+ assert not normal.regression
+
+
def test_benchmark_median():
assert median([10]) == 10
assert median([1, 2, 3]) == 2