mirror of https://github.com/google/benchmark.git
[Tooling] report.py: don't crash on BigO/RMS benchmarks
Run into this by accident while writing benchmark to validate the fix for https://bugs.llvm.org/show_bug.cgi?id=40965 Fixes #779.
This commit is contained in:
parent
d205ead299
commit
f62c63b14f
|
@ -97,6 +97,23 @@
|
|||
"real_time": 1,
|
||||
"cpu_time": 1,
|
||||
"time_unit": "s"
|
||||
},
|
||||
{
|
||||
"name": "MyComplexityTest_BigO",
|
||||
"run_name": "MyComplexityTest",
|
||||
"run_type": "aggregate",
|
||||
"aggregate_name": "BigO",
|
||||
"cpu_coefficient": 4.2749856294592886e+00,
|
||||
"real_coefficient": 6.4789275289789780e+00,
|
||||
"big_o": "N",
|
||||
"time_unit": "ns"
|
||||
},
|
||||
{
|
||||
"name": "MyComplexityTest_RMS",
|
||||
"run_name": "MyComplexityTest",
|
||||
"run_type": "aggregate",
|
||||
"aggregate_name": "RMS",
|
||||
"rms": 4.5097802512472874e-03
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -97,6 +97,23 @@
|
|||
"real_time": 1,
|
||||
"cpu_time": 1,
|
||||
"time_unit": "ns"
|
||||
},
|
||||
{
|
||||
"name": "MyComplexityTest_BigO",
|
||||
"run_name": "MyComplexityTest",
|
||||
"run_type": "aggregate",
|
||||
"aggregate_name": "BigO",
|
||||
"cpu_coefficient": 5.6215779594361486e+00,
|
||||
"real_coefficient": 5.6288314793554610e+00,
|
||||
"big_o": "N",
|
||||
"time_unit": "ns"
|
||||
},
|
||||
{
|
||||
"name": "MyComplexityTest_RMS",
|
||||
"run_name": "MyComplexityTest",
|
||||
"run_type": "aggregate",
|
||||
"aggregate_name": "RMS",
|
||||
"rms": 3.3128901852342174e-03
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -114,6 +114,10 @@ def intersect(list1, list2):
|
|||
return [x for x in list1 if x in list2]
|
||||
|
||||
|
||||
def is_potentially_comparable_benchmark(x):
|
||||
return ('time_unit' in x and 'real_time' in x and 'cpu_time' in x)
|
||||
|
||||
|
||||
def partition_benchmarks(json1, json2):
|
||||
"""
|
||||
While preserving the ordering, find benchmarks with the same names in
|
||||
|
@ -125,10 +129,17 @@ def partition_benchmarks(json1, json2):
|
|||
names = intersect(json1_unique_names, json2_unique_names)
|
||||
partitions = []
|
||||
for name in names:
|
||||
time_unit = None
|
||||
# Pick the time unit from the first entry of the lhs benchmark.
|
||||
time_unit = (x['time_unit']
|
||||
for x in json1['benchmarks'] if x['name'] == name).next()
|
||||
# We should be careful not to crash with unexpected input.
|
||||
for x in json1['benchmarks']:
|
||||
if (x['name'] == name and is_potentially_comparable_benchmark(x)):
|
||||
time_unit = x['time_unit']
|
||||
break
|
||||
if time_unit is None:
|
||||
break
|
||||
# Filter by name and time unit.
|
||||
# All the repetitions are assumed to be comparable.
|
||||
lhs = [x for x in json1['benchmarks'] if x['name'] == name and
|
||||
x['time_unit'] == time_unit]
|
||||
rhs = [x for x in json2['benchmarks'] if x['name'] == name and
|
||||
|
|
Loading…
Reference in New Issue