-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchtool.rkt
83 lines (75 loc) · 2.5 KB
/
benchtool.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
;; A benchmarking tool
#lang racket/base
(provide setup
do-bench
current-size)
(require racket/cmdline
racket/match
racket/string
racket/format
file/md5
pretty-expressive
pretty-expressive/doc
(only-in racket/pretty [pretty-write r:pretty-write]))
(define current-size (make-parameter #f))
(define current-out (make-parameter #f))
(define current-program (make-parameter #f))
(define current-view-cost? (make-parameter #f))
(define (setup program
#:size size
#:page-width [page-width 80]
#:computation-width [computation-width 100])
(current-page-width page-width)
(current-computation-width computation-width)
(current-size size)
(current-out #f)
(current-program program)
(current-view-cost? #f)
(command-line
#:once-each
[("--page-width")
page-width
[(format "Page width limit (default: ~a)" page-width)]
(current-page-width (string->number page-width))]
[("--computation-width")
computation-width
[(format "Computation width limit (default: ~a)" computation-width)]
(current-computation-width (string->number computation-width))]
[("--size")
size
[(format "Size (default: ~a)" size)]
(current-size (string->number size))]
[("--view-cost")
"Output cost (default: no)"
(current-view-cost? #t)]
[("--out")
out
"Path for the output; - means stdout (default: do not output)"
(current-out out)]
[("--memo-limit")
memo-limit
"Memoization limit (default: 7)"
(set-memo-limit! (string->number memo-limit))]))
;; do-bench :: doc? -> void?
(define (do-bench d)
(match-define-values [(list out (info tainted? cost)) _ duration _]
(time-apply (λ () (pretty-format/factory/info d (default-cost-factory))) '()))
(match (current-out)
[#f (void)]
["-" (displayln out)]
[dest (with-output-to-file dest
#:exists 'replace
(λ () (displayln out)))])
(when (current-view-cost?)
(fprintf (current-error-port) "(cost ~a)\n" cost))
(r:pretty-write
`([target pretty-expressive-racket]
[program ,(string->symbol (current-program))]
[duration ,(exact->inexact (/ duration 1000))]
[lines ,(length (string-split out "\n"))]
[size ,(current-size)]
[md5 ,(string->symbol (~a (md5 out)))]
[page-width ,(current-page-width)]
[computation-width ,(current-computation-width)]
[tainted? ,(if tainted? 'true 'false)]
[memo-limit ,(get-memo-limit)])))