#lang scheme/base
(require
(planet williams/science:3/science))
(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)))
#:exists 'replace)))
(define (find-most-recent-run file-name name)
(let ([log (read-benchmark-log file-name)])
(findf
(lambda (run)
(string=? (run-name run) name))
log)))