Last active
August 15, 2020 10:02
-
-
Save Hendekagon/37c86800ebdac4349be9623ac80b90d8 to your computer and use it in GitHub Desktop.
Testing arity vs map function call speed in clojure
This file contains hidden or 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
(defn add [x y] (+ x y))=> #'user/add(defn addm [{x :x y :y}] (+ x y))=> #'user/addm(reduce (fn [r i] (addm {:x r :y i})) 0 (range 128))=> 8128(quick-bench (reduce (fn [r i] (add r i)) 0 (range 128)))Evaluation count : 270720 in 6 samples of 45120 calls. Execution time mean : 2.212768 µs Execution time std-deviation : 76.515990 ns Execution time lower quantile : 2.130557 µs ( 2.5%) Execution time upper quantile : 2.336060 µs (97.5%) Overhead used : 1.902301 nsFound 1 outliers in 6 samples (16.6667 %) low-severe 1 (16.6667 %) Variance from outliers : 13.8889 % Variance is moderately inflated by outliers=> nil(quick-bench (reduce (fn [r i] (add r i)) 0 (range 128)))Evaluation count : 265158 in 6 samples of 44193 calls. Execution time mean : 2.323233 µs Execution time std-deviation : 176.530052 ns Execution time lower quantile : 2.223932 µs ( 2.5%) Execution time upper quantile : 2.626066 µs (97.5%) Overhead used : 1.902301 nsFound 1 outliers in 6 samples (16.6667 %) low-severe 1 (16.6667 %) Variance from outliers : 15.4138 % Variance is moderately inflated by outliers=> nil(quick-bench (reduce (fn [r i] (addm {:x r :y i})) 0 (range 128)))Evaluation count : 56208 in 6 samples of 9368 calls. Execution time mean : 11.928436 µs Execution time std-deviation : 950.653954 ns Execution time lower quantile : 10.705623 µs ( 2.5%) Execution time upper quantile : 13.069694 µs (97.5%) Overhead used : 1.902301 ns |
arity is several times faster than map args in Clojure.
Use arity on the inside for speed where the args are stable, use map args on the outside where you need the flexibility to change
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.