diff --git a/benchmarks/bench.scm b/benchmarks/bench.scm index 0d45fa8e4..4d801ae02 100644 --- a/benchmarks/bench.scm +++ b/benchmarks/bench.scm @@ -1,3 +1,5 @@ +(require "../cogs/srfi/srfi-28/format.scm") + (define print displayln) (define (build-release) @@ -9,9 +11,10 @@ (define *interpreter-map* (hash "py" "python3.13" - ;; "scm" "../target/release/steel" "scm" - "../target/aarch64-apple-darwin/release/steel" + "../target/release/steel" + ; "scm" + ; "../target/aarch64-apple-darwin/release/steel" "lua" "lua")) @@ -34,22 +37,55 @@ (run-bench (append (filter (lambda (x) (not (ends-with? x ".lua"))) (directory->bench-command dir)) options))) -(define *benches* - '(("startup" "--warmup" "10" "--min-runs" "100") ("map" "--warmup" "10") - ("ack" "--warmup" "10") - ("fib" "--warmup" "10" "--min-runs" "40") - ("bin-trees" "--warmup" "10"))) +(define *bench-hashmap* + (hash + "Startup" '("startup" "--warmup" "10" "--min-runs" "100") + "Map" '("map" "--warmup" "10") + "Ack" '("ack" "--warmup" "10") + "Fib" '("fib" "--warmup" "10" "--min-runs" "40") + "Binary Trees" '("bin-trees" "--warmup" "10") + )) + +(define *target-path* "../docs/src/benchmarks") + +(define (export-md arg-list) + (flatten (cons arg-list + (list "--export-markdown" + (format "~a/~a.md" *target-path* (car arg-list)))))) + +;; surely we don't need to define this +(define (repeat val times) + (map (λ (_) val) (range 0 times))) + +(define (write-newlines num port) + (#%raw-write-string (string-join (repeat "\n" num)) port)) + +;; TODO make sure the keys are ordered + +(define (build-benchmark-doc bench-hashmap) + (define out (open-output-file (format "~a/benchmarks.md" *target-path*))) + (#%raw-write-string "# Benchmarks" out) + (write-newlines 2 out) + (for-each (λ (key) (let ([name (car (hash-ref bench-hashmap key))]) + (#%raw-write-string (format "## ~a" key) out) + (write-newlines 2 out) + (#%raw-write-string (format "{{#include ~a.md}}" name) out) + (write-newlines 2 out))) + (hash-keys->list bench-hashmap)) + (close-port out)) (define (main) (print "Building steel for release...") (build-release) (print "Running benches...") - (transduce *benches* + (transduce (hash-values->list *bench-hashmap*) (mapping (lambda (args) (newline) - (apply bench-group args))) + (apply bench-group (export-md args)))) (into-list)) + (build-benchmark-doc *bench-hashmap*) + ; (bench-group "bin-trees") (print "Done")) diff --git a/benchmarks/fib/fib.py b/benchmarks/fib/fib.py index 430f8d959..f2be705de 100644 --- a/benchmarks/fib/fib.py +++ b/benchmarks/fib/fib.py @@ -5,6 +5,6 @@ def fib(n): return fib(n - 1) + fib(n - 2) start = time.time() -fib(35) +fib(40) end = time.time() print(end - start) diff --git a/benchmarks/fib/fib.scm b/benchmarks/fib/fib.scm index edc16b632..ac0eeb6d4 100644 --- a/benchmarks/fib/fib.scm +++ b/benchmarks/fib/fib.scm @@ -30,4 +30,4 @@ ;; ;; What that looks like -> Inlining a function call? -(fib 35) +(fib 40)