Created
October 3, 2012 17:17
-
-
Save samth/3828408 to your computer and use it in GitHub Desktop.
syntax-parse is slow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cpu time: 2269 real time: 2270 gc time: 1416 | |
cpu time: 416 real time: 417 gc time: 0 | |
cpu time: 184 real time: 184 gc time: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require syntax/parse) | |
(define f1 | |
(syntax-parser | |
#:literals (quote #%app) | |
[(quote #t) 1] | |
[(quote #f) 2] | |
[(#%app f) 3] | |
[(#%app f . x) 4] | |
[_ 5])) | |
(define f2 | |
(λ (stx) | |
(syntax-case stx (quote #%app) | |
[(quote #t) 1] | |
[(quote #f) 2] | |
[(#%app f) 3] | |
[(#%app f . x) 4] | |
[_ 5]))) | |
(define f3 | |
(λ (stx) | |
(match (syntax->list stx) | |
[`(,(? identifier? (== #'quote free-identifier=?)) ,(app syntax-e #t)) 1] | |
[`(,(? identifier? (== #'quote free-identifier=?)) ,(app syntax-e #f)) 2] | |
[`(,(? identifier? (== #'#%app free-identifier=?)) ,f) 3] | |
[`(,(? identifier? (== #'#%app free-identifier=?)) ,f . ,x) 4] | |
[_ 5]))) | |
(collect-garbage) (collect-garbage) (collect-garbage) | |
(time | |
(for ([i 100000]) | |
(f1 #'(#%app + 1 2)))) | |
(collect-garbage) (collect-garbage) (collect-garbage) | |
(time | |
(for ([i 100000]) | |
(f2 #'(#%app + 1 2)))) | |
(collect-garbage) (collect-garbage) (collect-garbage) | |
(time | |
(for ([i 100000]) | |
(f3 #'(#%app + 1 2)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment