Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active October 4, 2017 19:53
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 mfikes/862114a2c4675d6f0b375ac9212a7156 to your computer and use it in GitHub Desktop.
Save mfikes/862114a2c4675d6f0b375ac9212a7156 to your computer and use it in GitHub Desktop.
Speedup with ClojureScript printing negative 0 as -0
After adding
(zero? obj) (if (neg? (/ obj)) "-0" "0")
to the number? cond in pr-writer-impl, negative 0 prints as -0, and these
are the associated speedup benchmarks:
true 10 ##NaN ##Inf ##-Inf (js-obj) -0 0
V8: 1.03 1.02 1.04 1.02 1.00 1.06 1.06 1.07
SpiderMonkey: 0.99 1.00 1.01 1.02 1.02 1.08 1.04 1.01
JavaScriptCore: 1.03 1.01 0.79 0.99 1.01 1.00 0.94 0.93
Nashorn: 1.00 0.90 1.00 1.07 1.05 0.98 1.10 1.23
ChakraCore: 1.00 0.97 0.96 0.97 0.97 0.97 1.00 1.02
Before:
Benchmarking with V8
;; printing of numbers and handling of ##Nan, ##Inf, ##-Inf
[x true], (pr-str x), 1000000 runs, 393 msecs
[x 10], (pr-str x), 1000000 runs, 576 msecs
[x js/NaN], (pr-str x), 1000000 runs, 660 msecs
[x js/Infinity], (pr-str x), 1000000 runs, 637 msecs
[x js/-Infinity], (pr-str x), 1000000 runs, 591 msecs
[x (js-obj)], (pr-str x), 1000000 runs, 923 msecs
[x (/ js/-Infinity)], (pr-str x), 1000000 runs, 471 msecs
[x (/ js/Infinity)], (pr-str x), 1000000 runs, 560 msecs
Benchmarking with SpiderMonkey
;; printing of numbers and handling of ##Nan, ##Inf, ##-Inf
[x true], (pr-str x), 1000000 runs, 1344 msecs
[x 10], (pr-str x), 1000000 runs, 1293 msecs
[x js/NaN], (pr-str x), 1000000 runs, 1307 msecs
[x js/Infinity], (pr-str x), 1000000 runs, 1318 msecs
[x js/-Infinity], (pr-str x), 1000000 runs, 1352 msecs
[x (js-obj)], (pr-str x), 1000000 runs, 2301 msecs
[x (/ js/-Infinity)], (pr-str x), 1000000 runs, 1315 msecs
[x (/ js/Infinity)], (pr-str x), 1000000 runs, 1315 msecs
Benchmarking with JavaScriptCore
;; printing of numbers and handling of ##Nan, ##Inf, ##-Inf
[x true], (pr-str x), 1000000 runs, 513 msecs
[x 10], (pr-str x), 1000000 runs, 510 msecs
[x js/NaN], (pr-str x), 1000000 runs, 648 msecs
[x js/Infinity], (pr-str x), 1000000 runs, 695 msecs
[x js/-Infinity], (pr-str x), 1000000 runs, 716 msecs
[x (js-obj)], (pr-str x), 1000000 runs, 1213 msecs
[x (/ js/-Infinity)], (pr-str x), 1000000 runs, 791 msecs
[x (/ js/Infinity)], (pr-str x), 1000000 runs, 567 msecs
Benchmarking with Nashorn
;; printing of numbers and handling of ##Nan, ##Inf, ##-Inf
[x true], (pr-str x), 1000000 runs, 1653 msecs
[x 10], (pr-str x), 1000000 runs, 1309 msecs
[x js/NaN], (pr-str x), 1000000 runs, 1273 msecs
[x js/Infinity], (pr-str x), 1000000 runs, 1300 msecs
[x js/-Infinity], (pr-str x), 1000000 runs, 1254 msecs
[x (js-obj)], (pr-str x), 1000000 runs, 2959 msecs
[x (/ js/-Infinity)], (pr-str x), 1000000 runs, 1327 msecs
[x (/ js/Infinity)], (pr-str x), 1000000 runs, 1420 msecs
Benchmarking with ChakraCore
;; printing of numbers and handling of ##Nan, ##Inf, ##-Inf
[x true], (pr-str x), 1000000 runs, 1254 msecs
[x 10], (pr-str x), 1000000 runs, 1149 msecs
[x js/NaN], (pr-str x), 1000000 runs, 1082 msecs
[x js/Infinity], (pr-str x), 1000000 runs, 1096 msecs
[x js/-Infinity], (pr-str x), 1000000 runs, 1091 msecs
[x (js-obj)], (pr-str x), 1000000 runs, 2429 msecs
[x (/ js/-Infinity)], (pr-str x), 1000000 runs, 1143 msecs
[x (/ js/Infinity)], (pr-str x), 1000000 runs, 1156 msecs
After:
Benchmarking with V8
;; printing of numbers and handling of ##Nan, ##Inf, ##-Inf
[x true], (pr-str x), 1000000 runs, 380 msecs
[x 10], (pr-str x), 1000000 runs, 560 msecs
[x js/NaN], (pr-str x), 1000000 runs, 636 msecs
[x js/Infinity], (pr-str x), 1000000 runs, 624 msecs
[x js/-Infinity], (pr-str x), 1000000 runs, 593 msecs
[x (js-obj)], (pr-str x), 1000000 runs, 870 msecs
[x (/ js/-Infinity)], (pr-str x), 1000000 runs, 443 msecs
[x (/ js/Infinity)], (pr-str x), 1000000 runs, 522 msecs
Benchmarking with SpiderMonkey
;; printing of numbers and handling of ##Nan, ##Inf, ##-Inf
[x true], (pr-str x), 1000000 runs, 1352 msecs
[x 10], (pr-str x), 1000000 runs, 1291 msecs
[x js/NaN], (pr-str x), 1000000 runs, 1297 msecs
[x js/Infinity], (pr-str x), 1000000 runs, 1296 msecs
[x js/-Infinity], (pr-str x), 1000000 runs, 1328 msecs
[x (js-obj)], (pr-str x), 1000000 runs, 2132 msecs
[x (/ js/-Infinity)], (pr-str x), 1000000 runs, 1270 msecs
[x (/ js/Infinity)], (pr-str x), 1000000 runs, 1301 msecs
Benchmarking with JavaScriptCore
;; printing of numbers and handling of ##Nan, ##Inf, ##-Inf
[x true], (pr-str x), 1000000 runs, 499 msecs
[x 10], (pr-str x), 1000000 runs, 503 msecs
[x js/NaN], (pr-str x), 1000000 runs, 646 msecs
[x js/Infinity], (pr-str x), 1000000 runs, 700 msecs
[x js/-Infinity], (pr-str x), 1000000 runs, 708 msecs
[x (js-obj)], (pr-str x), 1000000 runs, 1212 msecs
[x (/ js/-Infinity)], (pr-str x), 1000000 runs, 840 msecs
[x (/ js/Infinity)], (pr-str x), 1000000 runs, 607 msecs
Benchmarking with Nashorn
;; printing of numbers and handling of ##Nan, ##Inf, ##-Inf
[x true], (pr-str x), 1000000 runs, 1648 msecs
[x 10], (pr-str x), 1000000 runs, 1460 msecs
[x js/NaN], (pr-str x), 1000000 runs, 1279 msecs
[x js/Infinity], (pr-str x), 1000000 runs, 1216 msecs
[x js/-Infinity], (pr-str x), 1000000 runs, 1191 msecs
[x (js-obj)], (pr-str x), 1000000 runs, 3025 msecs
[x (/ js/-Infinity)], (pr-str x), 1000000 runs, 1203 msecs
[x (/ js/Infinity)], (pr-str x), 1000000 runs, 1159 msecs
Benchmarking with ChakraCore
;; printing of numbers and handling of ##Nan, ##Inf, ##-Inf
[x true], (pr-str x), 1000000 runs, 1259 msecs
[x 10], (pr-str x), 1000000 runs, 1189 msecs
[x js/NaN], (pr-str x), 1000000 runs, 1124 msecs
[x js/Infinity], (pr-str x), 1000000 runs, 1135 msecs
[x js/-Infinity], (pr-str x), 1000000 runs, 1121 msecs
[x (js-obj)], (pr-str x), 1000000 runs, 2511 msecs
[x (/ js/-Infinity)], (pr-str x), 1000000 runs, 1141 msecs
[x (/ js/Infinity)], (pr-str x), 1000000 runs, 1136 msecs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment