string-append, conc and sprintf added by mario-goulart on Thu Mar 15 15:29:10 2012
(use data-structures) (define a) (define iters 1000000) (define (bench-string-append) (let loop ((i iters)) (when (> i 0) (set! a (string-append "a" "2")) (loop (fx- i 1))))) (define (bench-conc) (let loop ((i iters)) (when (> i 0) (set! a (conc "a" 2)) (loop (fx- i 1))))) (define (bench-sprintf) (let loop ((i iters)) (when (> i 0) (set! a (sprintf "a~A" 2)) (loop (fx- i 1))))) (print "=== string-append") (time (bench-string-append)) (newline) (print "=== conc") (time (bench-conc)) (newline) (print "=== sprintf") (time (bench-sprintf)) ;; $ csi -s ./bench.scm ;; === string-append ;; 0.888s CPU time, 0.096s GC time (major), 2000016 mutations, 115/11734 GCs (major/minor) ;; ;; === conc ;; 1.628s CPU time, 0.1s GC time (major), 6000016 mutations, 130/15870 GCs (major/minor) ;; ;; === sprintf ;; 3.844s CPU time, 1.336s GC time (major), 5000016 mutations, 1719/28075 GCs (major/minor) ;; $ csc -O2 bench.scm ;; $ ./bench ;; === string-append ;; 0.016s CPU time, 1000000 mutations ;; === conc ;; 1.14s CPU time, 0.184s GC time (major), 6000000 mutations, 298/7760 GCs (major/minor) ;; === sprintf ;; 2.868s CPU time, 1.204s GC time (major), 5000000 mutations, 1886/16981 GCs (major/minor)