Skip to content

Instantly share code, notes, and snippets.

@puredanger
Created February 3, 2017 17:48
Show Gist options
  • Save puredanger/88d0491cbb4dbf8fe98b3747963d0068 to your computer and use it in GitHub Desktop.
Save puredanger/88d0491cbb4dbf8fe98b3747963d0068 to your computer and use it in GitHub Desktop.
reduce + vs apply +
(def v0 [])
(def v10 (vec (range 10)))
(def v100 (vec (range 100)))
(def v1000 (vec (range 1000)))
(quick-bench (reduce + v0)) ;; 2 ns
(quick-bench (apply + v0)) ;; 29 ns
(quick-bench (reduce + v10)) ;; 216 ns
(quick-bench (apply + v10)) ;; 392 ns
(quick-bench (reduce + v100)) ;; 2.13 µs
(quick-bench (apply + v100)) ;; 2.38 µs
(quick-bench (reduce + v1000)) ;; 21.8 µs
(quick-bench (apply + v1000)) ;; 22.6 µs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment