Skip to content

Instantly share code, notes, and snippets.

@KeenS
Created May 28, 2014 22:55
Show Gist options
  • Save KeenS/35c0222e0e384f115f2c to your computer and use it in GitHub Desktop.
Save KeenS/35c0222e0e384f115f2c to your computer and use it in GitHub Desktop.
(import (scheme base)
(scheme time)
(scheme write)
(scheme file))
(define-syntax time
(syntax-rules ()
((time form)
(let ((start (current-jiffy)))
form
(/ (- (current-jiffy) start)
(jiffies-per-second))))))
(define write-bench-line
(lambda (n time file)
(display n file)
(display " " file)
(display time file)
(newline file)))
(define-syntax repeat
(syntax-rules ()
((repeat n form)
(let loop ((i n))
form
(if (< 0 i)
(loop (- i 1)))))))
(define write-bench
(lambda (append-log map-log n)
(let ((l (make-list n 0)))
(write-bench-line n (time (repeat 1000 (append l l))) append-log)
(write-bench-line n (time (repeat 1000 (map + l))) map-log))))
(let ((a (open-output-file "append.bench"))
(m (open-output-file "map.bench")))
(write-bench a m 1)
(write-bench a m 10)
(write-bench a m 100)
(write-bench a m 1000)
(write-bench a m 10000))
1 0.001322
10 0.010542
100 0.119637
1000 1.194813
10000 14.076053
1 0.006606
10 0.024532
100 0.210766
1000 2.171966
10000 23.605407
1 0.001201
10 0.003587
100 0.065481
1000 0.623790
10000 16.750385
1 0.006440
10 0.017967
100 0.150869
1000 1.550594
10000 18.000117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment