mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Benchmark script: use median AND mean of compile time
This commit is contained in:
parent
0837132ce3
commit
2049113935
@ -13,6 +13,9 @@ def median(lst):
|
|||||||
else:
|
else:
|
||||||
return (lst[mid - 1] + lst[mid]) / 2.0
|
return (lst[mid - 1] + lst[mid]) / 2.0
|
||||||
|
|
||||||
|
def mean(lst):
|
||||||
|
return float(sum(lst)) / max(len(lst), 1)
|
||||||
|
|
||||||
compiler_path = ''
|
compiler_path = ''
|
||||||
|
|
||||||
main_file = r'''
|
main_file = r'''
|
||||||
@ -69,7 +72,8 @@ def link_files():
|
|||||||
return end_t - start_t
|
return end_t - start_t
|
||||||
|
|
||||||
def benchmark(func):
|
def benchmark(func):
|
||||||
return median([func() for i in range(10)])
|
results = [func() for i in range(10)]
|
||||||
|
return mean(results), median(results)
|
||||||
|
|
||||||
def char_range(start, end):
|
def char_range(start, end):
|
||||||
for c in range(ord(start), ord(end)):
|
for c in range(ord(start), ord(end)):
|
||||||
@ -130,8 +134,8 @@ if args.generate_files:
|
|||||||
|
|
||||||
print('Time needed for ...')
|
print('Time needed for ...')
|
||||||
if args.benchmark_kind in ('all', 'main'):
|
if args.benchmark_kind in ('all', 'main'):
|
||||||
print(' ... compiling main: {:.2f} s'.format(benchmark(compile_main)))
|
print(' ... compiling main, mean: {:.2f}, median: {:.2f} s'.format(*benchmark(compile_main)))
|
||||||
if args.benchmark_kind in ('all', 'files'):
|
if args.benchmark_kind in ('all', 'files'):
|
||||||
print(' ... compiling test files: {:.2f} s'.format(benchmark(compile_files)))
|
print(' ... compiling test files, mean: {:.2f}, median: {:.2f} s'.format(*benchmark(compile_files)))
|
||||||
if args.benchmark_kind in ('all', 'link'):
|
if args.benchmark_kind in ('all', 'link'):
|
||||||
print(' ... linking everything: {:.2f} s'.format(benchmark(link_files)))
|
print(' ... linking everything, mean: {:.2f}, median: {:.2f} s'.format(*benchmark(link_files)))
|
||||||
|
Loading…
Reference in New Issue
Block a user