Last active
August 29, 2015 14:26
-
-
Save Metaxal/4beb286cacc0966b433a to your computer and use it in GitHub Desktop.
Stress test for JIT optimizations of closures and conditionals
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 | |
(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