add `report/time` and `time-name`

dev-refac-2020
Matthew Butterick 7 years ago
parent 75ac017fee
commit 805ae055c6

@ -1,7 +1,8 @@
#lang racket/base #lang racket/base
(require racket/string (for-syntax racket/base) "define.rkt") (require racket/string (for-syntax racket/base) "define.rkt")
(provide+safe report report/line report/file (provide+safe report report/time time-name
report/line report/file
report* report*/line report*/file report* report*/line report*/file
report-apply repeat time-repeat time-repeat* compare) report-apply repeat time-repeat time-repeat* compare)
@ -20,6 +21,17 @@
(apply values expr-results))])) (apply values expr-results))]))
(define-syntax (report/time stx)
(syntax-case stx ()
[(MACRO EXPR) #'(MACRO EXPR EXPR)]
[(_ EXPR NAME)
#'(let* ([op (open-output-string)]
[expr-results (parameterize ([current-output-port op])
(time (call-with-values (λ () EXPR) list)))])
(eprintf "~a = ~a [~a]\n" 'NAME (stringify-results expr-results) (string-trim (get-output-string op)))
(apply values expr-results))]))
(define-syntax (report/line stx) (define-syntax (report/line stx)
(syntax-case stx () (syntax-case stx ()
[(MACRO EXPR) #'(MACRO EXPR EXPR)] [(MACRO EXPR) #'(MACRO EXPR EXPR)]
@ -78,6 +90,16 @@
(values (time-repeat n EXPR) ...))])) (values (time-repeat n EXPR) ...))]))
(define-syntax (time-name stx)
(syntax-case stx ()
[(_ NAME EXPR ...)
#'(let* ([op (open-output-string)]
[expr-results (parameterize ([current-output-port op])
(time (call-with-values (λ () EXPR ...) values)))])
(display (format "~a: ~a" 'NAME (get-output-string op)))
expr-results)]))
(define-syntax (compare stx) (define-syntax (compare stx)
(syntax-case stx () (syntax-case stx ()
[(_ EXPR ID ID-ALT ...) [(_ EXPR ID ID-ALT ...)

Loading…
Cancel
Save