diff --git a/README.md b/README.md index 13c7111..5c03d97 100644 --- a/README.md +++ b/README.md @@ -103,13 +103,12 @@ These tests usually compare the implementations of *AYMO* with those of other ex ## Benchmarking -**This feature is still under heavy development.** - -A basic benchmark suite is run via the `meson test --benchmark` command: +A basic benchmark suite is run via the following commands: ```sh cd PATH_TO_PROJECT_ROOT/builddir meson test --benchmark +meson compile benchmark-report ``` diff --git a/apps/aymo_ymf262_play.c b/apps/aymo_ymf262_play.c index 16e0794..5199f61 100644 --- a/apps/aymo_ymf262_play.c +++ b/apps/aymo_ymf262_play.c @@ -570,7 +570,7 @@ static int app_run(void) if (app_args.benchmark) { clock_t clock_duration = (clock_end - clock_start); double seconds = ((double)clock_duration * (1. / (double)CLOCKS_PER_SEC)); - printf("Render time: %.3f seconds\n", seconds); + printf("Render time: %.6f seconds\n", seconds); } return 0; diff --git a/benchmarks/export_report.py b/benchmarks/export_report.py new file mode 100644 index 0000000..bda3aea --- /dev/null +++ b/benchmarks/export_report.py @@ -0,0 +1,66 @@ +import json +import os +import sys +from contextlib import redirect_stdout + +__thin__ = '-' * 80 + +if __name__ == '__main__': + inpath = sys.argv[1] + outpath = sys.argv[2] + + with open(inpath, 'rt') as infile: + lines = infile.readlines() + + durations = {} + cpuexts = set() + + for index, line in enumerate(lines): + print(__thin__) + print(f'Entry: {1+index:3d} / {len(lines):3d}') + + info = json.loads(line) + + cmdline = info['command'] + score = os.path.basename(cmdline[-1]) + cpuext = cmdline[cmdline.index('--cpu-ext')+1] + exit_code = info['returncode'] + + print(f'Score: {score!r}') + print(f'CPU-ext: {cpuext}') + print(f'Command: {cmdline}') + print(f'Exit-code: {exit_code}') + assert not exit_code + + cpuexts.add(cpuext) + stdout = info['stdout'] + rtidx = stdout.index('Render time:') + sidx = stdout.index('seconds', rtidx) + duration = float(stdout[rtidx+12:sidx]) + print(f'Duration: {duration} seconds') + + if score not in durations: + durations[score] = {} + durations[score][cpuext] = duration + + cpuexts.remove('dummy') + cpuexts.remove('none') + cpuexts = ['dummy', 'none'] + list(sorted(cpuexts)) + totals = {cpuext: 0 for cpuext in cpuexts} + + durations = {score: durations[score] for score in sorted(durations, key=lambda x: x.lower())} + + with open(outpath, 'wt') as outfile: + outfile.write(f'SCORE') + for cpuext in cpuexts: + outfile.write(f',{cpuext}') + outfile.write('\n') + + for score, values in durations.items(): + score = score.replace('"', '\\"') + outfile.write(f'"{score}"') + for cpuext in cpuexts: + duration = values[cpuext] + outfile.write(f',{duration:.6f}') + totals[cpuext] += duration + outfile.write('\n') diff --git a/benchmarks/meson.build b/benchmarks/meson.build index 9fec175..2473add 100644 --- a/benchmarks/meson.build +++ b/benchmarks/meson.build @@ -127,3 +127,15 @@ foreach intr_name : ['dummy', 'none', 'x86_sse41', 'x86_avx2', 'arm_neon'] endforeach endif endforeach + +# Strictly run: +# meson test --benchmark +run_target( + 'benchmark-report', + command: [ + python_exe, + join_paths(top_srcdir, 'benchmarks', 'export_report.py'), + join_paths(top_builddir, 'meson-logs', 'testlog.json'), + join_paths(top_builddir, 'benchmarks', 'report.csv') + ] +) diff --git a/meson.build b/meson.build index c04b104..c88e84f 100644 --- a/meson.build +++ b/meson.build @@ -66,12 +66,14 @@ libversion = '0.0.2' cc = meson.get_compiler('c') host_system = host_machine.system() host_cpu_family = host_machine.cpu_family() -top_srcdir = meson.current_source_dir() # for opt_docs -top_builddir = meson.current_build_dir() # for opt_docs +top_srcdir = meson.current_source_dir() +top_builddir = meson.current_build_dir() aymo_includes = include_directories('.', 'include') aymo_public_includes = include_directories('include') +python_exe = find_program('python', 'python3') + # ===================================================================== add_project_arguments('-DAYMO_BUILD=1', language: 'c')