diff --git a/Makefile b/Makefile index 6f576181d5..d080d89819 100644 --- a/Makefile +++ b/Makefile @@ -257,3 +257,10 @@ smoke: install submodules .PHONY : changelog changelog : @github_changelog_generator + +HYPERFINEBIN := $(shell command -v hyperfine 2> /dev/null) + +.PHONY : hyperfine-benchmarks +hyperfine-benchmarks: + @$(if $(HYPERFINEBIN),, $(error "hyperfine not found, please install it using cargo or from https://github.com/sharkdp/hyperfine")) + cd bench/hyperfine && ${MAKE} diff --git a/bench/hyperfine/.gitignore b/bench/hyperfine/.gitignore new file mode 100644 index 0000000000..a646ec39db --- /dev/null +++ b/bench/hyperfine/.gitignore @@ -0,0 +1,3 @@ +*.md +*.json +*.png diff --git a/bench/hyperfine/Makefile b/bench/hyperfine/Makefile new file mode 100644 index 0000000000..28052d13d7 --- /dev/null +++ b/bench/hyperfine/Makefile @@ -0,0 +1,46 @@ +HELL := /bin/bash +HYPERFINE?=hyperfine +WARMUP?=2 +RUNS?=10 +HYPERFINEFLAGS?=--warmup ${WARMUP} \ + --runs ${RUNS} + +JUVIXVERSIONS?=-v0.4.3,-v0.5.0,-v0.5.1,-v0.5.2,-v0.5.3,-v0.5.4, +TASKS?="dev root" \ + "dev parse" \ + "dev highlight" \ + typecheck \ + "compile -o /dev/null" \ + "compile -o /dev/null -t wasm32-wasi" \ + "compile -o /dev/null -t core" \ + "compile -o /dev/null -t asm" \ + eval + +GLOBALOPTS?= + +FILENAME?=fibo.juvix + +all: hyperfine + +.PHONY: hyperfine +hyperfine: + @echo "# Hyperfine Benchmarks" > README.md + @for task in ${TASKS}; do \ + TASK=$$task ${MAKE} run; \ + done; + +.PHONY: run +run: + @${HYPERFINE} ${HYPERFINEFLAGS} \ + --parameter-list version ${JUVIXVERSIONS} \ + 'juvix{version} ${TASK} ${FILENAME} ${GLOBALOPTS}' \ + --export-markdown TMP.md + @echo "" >> README.md + @echo "## ${TASK}" >> README.md + @echo "" >> README.md + @cat TMP.md >> README.md + rm -f TMP.md + +.PHONY: clean +clean: + @rm -rf *.json *.md diff --git a/bench/hyperfine/fibo.juvix b/bench/hyperfine/fibo.juvix new file mode 100644 index 0000000000..174174cf9f --- /dev/null +++ b/bench/hyperfine/fibo.juvix @@ -0,0 +1,11 @@ +module fibo; + +import Stdlib.Prelude open; + +fib : Nat → Nat → Nat → Nat + | zero x1 _ := x1 + | (suc n) x1 x2 := fib n x2 (x1 + x2); + +fibonacci (n : Nat) : Nat := fib n 0 1; + +main : IO := printNatLn (fibonacci 50);