Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Metaxal
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Metaxal/4beb286cacc0966b433a to your computer and use it in GitHub Desktop.
Save Metaxal/4beb286cacc0966b433a to your computer and use it in GitHub Desktop.
Stress test for JIT optimizations of closures and conditionals
#lang racket
(define ((foo #:a? [a? #t] #:b? [b? #t]) x)
(when b?
(displayln "b!"))
(if a?
(+ x 1)
(+ x 2)))
(define fooanb (foo #:b? #f))
(define foonab (foo #:a? #f))
(define foonanb (foo #:a? #f #:b? #f))
;; No keyword versions:
(define (fooanb2 x)
(+ x 1))
(define (foonab2 x)
(displayln "b!")
(+ x 2))
(define (foonanb2 x)
(+ x 2))
(time (for ([i 100000000]) (fooanb i))) ; cpu time: 4208 real time: 4209 gc time: 0
(time (for ([i 100000000]) (fooanb2 i))) ; cpu time: 3312 real time: 3313 gc time: 0
(time (for ([i 100000000]) (foonanb i))) ; cpu time: 4147 real time: 4147 gc time: 0
(time (for ([i 100000000]) (foonanb2 i))) ; cpu time: 3332 real time: 3333 gc time: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment