(module benchmark-log mzscheme
(require
(lib "list.ss" "srfi" "1")
(planet williams/science:3/science)
(planet "port.ss" ("schematics" "port.plt" 1)))
(provide
run-name
run-times
read-benchmark-log
add-run
find-most-recent-run)
(define (run-name run)
(vector-ref run 0))
(define (run-times run)
(vector-ref run 3))
(define (read-benchmark-log file-name)
(if (file-exists? file-name)
(with-input-from-file file-name
(lambda ()
(read (current-input-port))))
(begin
(with-output-to-file file-name
(lambda () (write null)))
null)))
(define (add-run file-name name times)
(let ([data (read-benchmark-log file-name)])
(with-output-to-file file-name
(lambda ()
(write
(cons
(vector name "" (current-seconds) times (mean times) (standard-deviation times))
data)))
'replace)))
(define (find-most-recent-run file-name name)
(let ([log (read-benchmark-log file-name)])
(find
(lambda (run)
(string=? (run-name run) name))
log)))
)