AtlatestRepositorysigil-markdown
1;;; Benchmark harness for (sigil markdown)
2;;;
3;;; Usage: sigil bench/bench.sgl
4;;;
5;;; Times markdown->sxml on representative corpus docs and prints a
6;;; per-function profile of the hot path.
7
8(import (sigil markdown)
9 (sigil time)
10 (sigil fs)
11 (sigil string)
12 (sigil profile))
14;; Repeat a string n times (to build a large representative note).
15(define (string-repeat s n)
16 (let loop ((i 0) (acc '()))
17 (if (>= i n)
18 (string-join acc "\n\n")
19 (loop (+ i 1) (cons s acc)))))
21(define mixed (read-file-string "bench/corpus/mixed.md"))
23;; A "large folio note": the mixed doc repeated to a realistic size.
24(define large (string-repeat mixed 20))
26(define (bench-doc name text iters)
27 ;; warmup
28 (markdown->sxml text)
29 (let* ((jps (jiffies-per-second))
30 (start (current-jiffy)))
31 (let loop ((i 0))
32 (when (< i iters)
33 (markdown->sxml text)
34 (loop (+ i 1))))
35 (let* ((end (current-jiffy))
36 (total-ms (* 1000.0 (/ (- end start) jps)))
37 (per-ms (/ total-ms iters))
38 (kb (/ (string-length text) 1024.0)))
39 (println "~a: ~a ms/render (~a KB, ~a iters)"
40 name per-ms kb iters))))
42(println "=== Timing ===")
43(bench-doc "mixed" mixed 200)
44(bench-doc "large" large 20)
46(println "")
47(println "=== Profile (large doc, 20 renders) ===")
48(profile-reset)
49(profile-start)
50(let loop ((i 0))
51 (when (< i 20)
52 (markdown->sxml large)
53 (loop (+ i 1))))
54(profile-stop)
55(profile-report 25)