Skip to content

@samth /sp.rkt
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
syntax-parse is slow
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
#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
Something went wrong with that request. Please try again.