|
28 | 28 | (define iter 0) |
29 | 29 | (define last #f) |
30 | 30 | (for/list ([exec (in-vector execs)]) |
31 | | - (match-define (execution name id precision time _ _) exec) |
| 31 | + (define id (execution-number exec)) |
32 | 32 | (when (and last (< id last)) |
33 | 33 | (set! iter (+ iter 1))) |
34 | 34 | (set! last id) |
|
40 | 40 | (display (~a (fn row col) #:width width #:align 'right))) |
41 | 41 | (newline))) |
42 | 42 |
|
43 | | -(define-syntax-rule (list-find-match l pattern body ...) |
44 | | - (let loop ([l l]) |
45 | | - (match l |
46 | | - [(cons pattern rest) |
47 | | - body ...] |
48 | | - [(cons _ rest) (loop rest)] |
49 | | - ['() ""]))) |
| 43 | +(define (lookup-execution execs |
| 44 | + #:iter [target-iter #f] |
| 45 | + #:id [target-id #f] |
| 46 | + #:name [target-name #f] |
| 47 | + #:default [default ""] |
| 48 | + #:value [value (lambda (_iter exec) exec)]) |
| 49 | + (define entry |
| 50 | + (for/first ([exec (in-list execs)] |
| 51 | + #:when (and (or (not target-iter) (= (car exec) target-iter)) |
| 52 | + (or (not target-id) (= (execution-number (cdr exec)) target-id)) |
| 53 | + (or (not target-name) (= (execution-name (cdr exec)) target-name)))) |
| 54 | + exec)) |
| 55 | + (if entry |
| 56 | + (value (car entry) (cdr entry)) |
| 57 | + default)) |
50 | 58 |
|
51 | 59 | (struct repl ([precision #:mutable] context)) |
52 | 60 |
|
|
88 | 96 | (printf "Executed ~a instructions for ~a iterations:\n\n" num-instructions num-iterations) |
89 | 97 |
|
90 | 98 | (define execs* (executions-iterations execs)) |
91 | | - (write-table #:rows (+ 5 num-instructions) ; 1 for the "adjust" row |
92 | | - #:cols (+ 1 (* 2 num-iterations)) |
93 | | - #:width 6 |
94 | | - (lambda (row col) |
95 | | - (match* (row col) |
96 | | - [(0 0) ""] |
97 | | - [(0 col) |
98 | | - #:when (= (modulo col 2) 1) |
99 | | - "Bits"] |
100 | | - [(0 col) |
101 | | - #:when (= (modulo col 2) 0) |
102 | | - "Time"] |
103 | | - [(1 _) "------"] |
104 | | - [(2 0) 'adjust] |
105 | | - [(2 col) |
106 | | - #:when (and (= (modulo col 2) 0) (> col 2)) |
107 | | - (define iter (- (/ col 2) 1)) |
108 | | - (list-find-match execs* |
109 | | - (cons (== iter) (execution 'adjust _ _ time _ _)) |
110 | | - (~r (* time 1000) #:precision '(= 1)))] |
111 | | - [(2 col) ""] |
112 | | - [((== (+ 3 num-instructions)) _) "------"] |
113 | | - [((== (+ 4 num-instructions)) 0) "Total"] |
114 | | - [((== (+ 4 num-instructions)) col) |
115 | | - #:when (= (modulo col 2) 1) |
116 | | - ""] |
117 | | - [((== (+ 4 num-instructions)) col) |
118 | | - #:when (= (modulo col 2) 0) |
119 | | - (define iter (/ (- col 2) 2)) |
120 | | - (define time |
121 | | - (apply + |
122 | | - (for/list ([exec (in-list execs*)] |
123 | | - #:when (= (car exec) iter)) |
124 | | - (execution-time (cdr exec))))) |
125 | | - (~r (* time 1000) #:precision '(= 1))] |
126 | | - [(row 0) |
127 | | - (define id (+ (- row 3) num-args)) |
128 | | - (list-find-match execs* |
129 | | - (cons _ (execution name (== id) _ _ _ _)) |
130 | | - (normalize-function-name (~a name)))] |
131 | | - [(row col) |
132 | | - #:when (= (modulo col 2) 1) ; precision |
133 | | - (define id (+ (- row 3) num-args)) |
134 | | - (define iter (/ (- col 1) 2)) |
135 | | - (list-find-match execs* (cons (== iter) (execution _ (== id) prec _ _ _)) prec)] |
136 | | - [(row col) |
137 | | - #:when (= (modulo col 2) 0) ; time |
138 | | - (define id (+ (- row 3) num-args)) |
139 | | - (define iter (/ (- col 2) 2)) |
140 | | - (list-find-match execs* |
141 | | - (cons (== iter) (execution _ (== id) _ time _ _)) |
142 | | - (~r (* time 1000) #:precision '(= 1)))])))) |
| 99 | + (write-table |
| 100 | + #:rows (+ 5 num-instructions) ; 1 for the "adjust" row |
| 101 | + #:cols (+ 1 (* 2 num-iterations)) |
| 102 | + #:width 6 |
| 103 | + (lambda (row col) |
| 104 | + (match* (row col) |
| 105 | + [(0 0) ""] |
| 106 | + [(0 col) |
| 107 | + #:when (= (modulo col 2) 1) |
| 108 | + "Bits"] |
| 109 | + [(0 col) |
| 110 | + #:when (= (modulo col 2) 0) |
| 111 | + "Time"] |
| 112 | + [(1 _) "------"] |
| 113 | + [(2 0) 'adjust] |
| 114 | + [(2 col) |
| 115 | + #:when (and (= (modulo col 2) 0) (> col 2)) |
| 116 | + (define iter (- (/ col 2) 1)) |
| 117 | + (lookup-execution execs* |
| 118 | + #:iter iter |
| 119 | + #:name 'adjust |
| 120 | + #:default "" |
| 121 | + #:value (lambda (_iter exec) |
| 122 | + (~r (* (execution-time exec) 1000) #:precision '(= 1))))] |
| 123 | + [(2 col) ""] |
| 124 | + [((== (+ 3 num-instructions)) _) "------"] |
| 125 | + [((== (+ 4 num-instructions)) 0) "Total"] |
| 126 | + [((== (+ 4 num-instructions)) col) |
| 127 | + #:when (= (modulo col 2) 1) |
| 128 | + ""] |
| 129 | + [((== (+ 4 num-instructions)) col) |
| 130 | + #:when (= (modulo col 2) 0) |
| 131 | + (define iter (/ (- col 2) 2)) |
| 132 | + (define time |
| 133 | + (apply + |
| 134 | + (for/list ([exec (in-list execs*)] |
| 135 | + #:when (= (car exec) iter)) |
| 136 | + (execution-time (cdr exec))))) |
| 137 | + (~r (* time 1000) #:precision '(= 1))] |
| 138 | + [(row 0) |
| 139 | + (define id (+ (- row 3) num-args)) |
| 140 | + (lookup-execution execs* |
| 141 | + #:id id |
| 142 | + #:default "" |
| 143 | + #:value (lambda (_iter exec) |
| 144 | + (normalize-function-name (~a (execution-name exec)))))] |
| 145 | + [(row col) |
| 146 | + #:when (= (modulo col 2) 1) ; precision |
| 147 | + (define id (+ (- row 3) num-args)) |
| 148 | + (define iter (/ (- col 1) 2)) |
| 149 | + (lookup-execution execs* |
| 150 | + #:iter iter |
| 151 | + #:id id |
| 152 | + #:default "" |
| 153 | + #:value (lambda (_iter exec) (execution-precision exec)))] |
| 154 | + [(row col) |
| 155 | + #:when (= (modulo col 2) 0) ; time |
| 156 | + (define id (+ (- row 3) num-args)) |
| 157 | + (define iter (/ (- col 2) 2)) |
| 158 | + (define value |
| 159 | + (lookup-execution execs* |
| 160 | + #:iter iter |
| 161 | + #:id id |
| 162 | + #:default "" |
| 163 | + #:value (lambda (_iter exec) |
| 164 | + (~r (* (execution-time exec) 1000) #:precision '(= 1))))) |
| 165 | + value])))) |
143 | 166 |
|
144 | 167 | (define (rival-repl p) |
145 | 168 | (let/ec k |
|
0 commit comments