Skip to content

Commit

Permalink
Added benchmark report
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Zoppi <texzk@email.it>
  • Loading branch information
TexZK committed Mar 31, 2024
1 parent 0dfbb7d commit 94e50d3
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 6 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


Expand Down
2 changes: 1 addition & 1 deletion apps/aymo_ymf262_play.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
66 changes: 66 additions & 0 deletions benchmarks/export_report.py
Original file line number Diff line number Diff line change
@@ -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')
12 changes: 12 additions & 0 deletions benchmarks/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
]
)
6 changes: 4 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 94e50d3

Please sign in to comment.