diff options
author | Marvin Borner | 2024-02-29 14:56:18 +0100 |
---|---|---|
committer | Marvin Borner | 2024-02-29 14:56:18 +0100 |
commit | d64bbff1f00e31a92031a44395958a360c93171b (patch) | |
tree | b92266b3def06f4142d621e52752eddf85679320 /benchmarks/by-n | |
parent | b13bc3379a46cc5e45eeede0537f0da323410d85 (diff) |
Added benchmarks
Diffstat (limited to 'benchmarks/by-n')
-rw-r--r-- | benchmarks/by-n/.gitignore | 3 | ||||
-rw-r--r-- | benchmarks/by-n/fac.bruijn | 5 | ||||
-rw-r--r-- | benchmarks/by-n/metafac.bruijn | 6 | ||||
-rw-r--r-- | benchmarks/by-n/omega.bruijn | 5 | ||||
-rwxr-xr-x | benchmarks/by-n/plot.py | 32 | ||||
-rw-r--r-- | benchmarks/by-n/prime.bruijn | 6 | ||||
-rwxr-xr-x | benchmarks/by-n/run.sh | 11 |
7 files changed, 68 insertions, 0 deletions
diff --git a/benchmarks/by-n/.gitignore b/benchmarks/by-n/.gitignore new file mode 100644 index 0000000..f550ac1 --- /dev/null +++ b/benchmarks/by-n/.gitignore @@ -0,0 +1,3 @@ +temp.bruijn +*.json +*.png diff --git a/benchmarks/by-n/fac.bruijn b/benchmarks/by-n/fac.bruijn new file mode 100644 index 0000000..318dafd --- /dev/null +++ b/benchmarks/by-n/fac.bruijn @@ -0,0 +1,5 @@ +# 0 10 40 + +:import std/Math . + +main [fac (+${BENCH_N})] diff --git a/benchmarks/by-n/metafac.bruijn b/benchmarks/by-n/metafac.bruijn new file mode 100644 index 0000000..1c81cdf --- /dev/null +++ b/benchmarks/by-n/metafac.bruijn @@ -0,0 +1,6 @@ +# 0 5 20 + +:import std/Math . +:import std/Meta . + +main [!`(fac (+${BENCH_N}))] diff --git a/benchmarks/by-n/omega.bruijn b/benchmarks/by-n/omega.bruijn new file mode 100644 index 0000000..3d72446 --- /dev/null +++ b/benchmarks/by-n/omega.bruijn @@ -0,0 +1,5 @@ +# 0 7 + +:import std/Combinator . + +main [ω (+${BENCH_N}u)] diff --git a/benchmarks/by-n/plot.py b/benchmarks/by-n/plot.py new file mode 100755 index 0000000..ba96a0c --- /dev/null +++ b/benchmarks/by-n/plot.py @@ -0,0 +1,32 @@ +#!/bin/env python3 + +import matplotlib.pyplot as plt +import json +import os, glob + + +def render(file): + data = json.load(open(file, "r"))["results"] + basename = os.path.basename(file).split(".")[0] + reducers = list({p["parameters"]["REDUCER"] for p in data}) + for reducer in reducers: + labels = [ + p["parameters"]["N"] + for p in data + if p["parameters"]["REDUCER"] == reducer + ] + times = [ + p["median"] for p in data if p["parameters"]["REDUCER"] == reducer + ] + plt.plot(times) + plt.xticks(range(len(labels)), labels) + plt.legend(reducers) + plt.title(f"reducer comparison for {basename}") + plt.xlabel("N") + plt.ylabel("Time (s)") + plt.savefig(f"{basename}.png") + plt.close() + + +for file in glob.glob("*.json"): + render(file) diff --git a/benchmarks/by-n/prime.bruijn b/benchmarks/by-n/prime.bruijn new file mode 100644 index 0000000..ed41bc3 --- /dev/null +++ b/benchmarks/by-n/prime.bruijn @@ -0,0 +1,6 @@ +# 0 40 200 + +:import std/Math . +:import std/List . + +main [primes !! (+${BENCH_N})] diff --git a/benchmarks/by-n/run.sh b/benchmarks/by-n/run.sh new file mode 100755 index 0000000..65f7af8 --- /dev/null +++ b/benchmarks/by-n/run.sh @@ -0,0 +1,11 @@ +#!/bin/env sh + +rm -rf temp.bruijn *.json +for file in $(find . -type f -name "*.bruijn" | sort); do + echo "testing $file" + spec=$(head -n 1 "$file") + range=${spec#??} + nseq=$(seq -s, $range) # requires splitting, no quotes! + reducers=$(find ../../src/Reducer/ -type f -name "*.hs" -exec basename {} .hs \; | paste -sd, -) + hyperfine --export-json "$file.json" --warmup 3 -r 3 -L REDUCER "$reducers" -L N $nseq "BENCH_N={N} envsubst <$file >temp.bruijn; bruijn -y -r {REDUCER} temp.bruijn </dev/null &>/dev/null;" +done |