AtlatestRepositorysigil-format
sigil-format / tree / benchbench-perf.sgl
1
;;; Single measurement in a fresh process: BENCH_IMPL=cli|local BENCH_LINES=n2
;;; Runs the tokenizer twice and reports both (first = cold, second = warm).4
(import (sigil core)5
(sigil io)6
(sigil env)7
(sigil time)8
(prefix (sigil format tokenize) cli:)9
(prefix (sigil format tokenize2) local:))11
(define (gen-source n-lines)12
(call-with-output-string13
(lambda (p)14
(let loop ((i 0))15
(when (< i n-lines)16
(write-string "(define (fn-" p)17
(write-string (number->string i) p)18
(write-string " x) ; comment here\n (+ x " p)19
(write-string (number->string i) p)20
(write-string " \"str\"))\n" p)21
(loop (+ i 1)))))))23
(define impl (or (getenv "BENCH_IMPL") "new"))24
(define n-lines (string->number (or (getenv "BENCH_LINES") "1000")))26
(define src (gen-source n-lines))28
(define (run!)29
(if (string=? impl "cli")30
(cli:tokenize src "b.sgl") ; the sigil CLI's embedded version31
(local:tokenize src "b.sgl"))) ; the local build (via the tokenize2 copy)33
(display impl)34
(display " lines=") (display n-lines)35
(display " chars=") (display (string-length src))36
(display " runs=")37
(let loop ((k 0) (best #f))38
(if (>= k 3)39
(begin (display " min=") (display best) (display "ms") (newline))40
(let* ((t0 (current-milliseconds))41
(r (run!))42
(t1 (current-milliseconds))43
(ms (- t1 t0)))44
(display ms) (display " ")45
(loop (+ k 1) (if (or (not best) (< ms best)) ms best)))))