Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active June 17, 2017 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfikes/c5ff1ab15d8af50c31ad9a2834892400 to your computer and use it in GitHub Desktop.
Save mfikes/c5ff1ab15d8af50c31ad9a2834892400 to your computer and use it in GitHub Desktop.

The case example in ClojureScript Case Constants is now an order of magnitude faster in ClojureScript master, due to a change by David Nolen to inline constants!

Old:

cljs.user=> (def ^:const n 3)
#'cljs.user/n
cljs.user=> (def ^:const m 4)
#'cljs.user/m
cljs.user=> (defn foo []
       #_=>  (let [x 4]
       #_=>    (case x
       #_=>      n 1
       #_=>      m 2
       #_=>      7 3
       #_=>      "hi" 4
       #_=>      :no-match)))
#'cljs.user/foo
cljs.user=> (simple-benchmark [] (foo) 100000000)
[], (foo), 100000000 runs, 374 msecs
nil
cljs.user=> (simple-benchmark [] (foo) 100000000)
[], (foo), 100000000 runs, 375 msecs
nil

New:

cljs.user=> (def ^:const n 3)
       #_=> (def ^:const m 4)
#'cljs.user/n
#'cljs.user/m
cljs.user=> (defn foo []
       #_=>  (let [x 4]
       #_=>    (case x
       #_=>      n 1
       #_=>      m 2
       #_=>      7 3
       #_=>      "hi" 4
       #_=>      :no-match)))
#'cljs.user/foo
cljs.user=> (simple-benchmark [] (foo) 100000000)
[], (foo), 100000000 runs, 31 msecs
nil
cljs.user=> (simple-benchmark [] (foo) 100000000)
[], (foo), 100000000 runs, 30 msecs
nil
cljs.user=> (simple-benchmark [] (foo) 100000000)
[], (foo), 100000000 runs, 36 msecs
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment