Skip to content

Instantly share code, notes, and snippets.

@mrrodriguez
Created May 6, 2014 18:56
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 mrrodriguez/e2138f220a9aa7eacc20 to your computer and use it in GitHub Desktop.
Save mrrodriguez/e2138f220a9aa7eacc20 to your computer and use it in GitHub Desktop.
Comparing clj record ctor options performance
(defrecord MyTest [a b c d e f g h i j])
;= user.MyTest
(time (dotimes [_ 10000000]
(new MyTest 1 2 3 4 5 6 7 8 9 10)))
;= "Elapsed time: 11.227 msecs"
;= nil
(time (dotimes [_ 10000000]
(->MyTest 1 2 3 4 5 6 7 8 9 10)))
;= "Elapsed time: 17.319 msecs"
;= nil
(time (dotimes [_ 10000000]
(map->MyTest {:a 1 :b 2 :c 3 :d 4 :e 5 :f 6 :g 7 :h 8 :i 9 :j 10})))
;= "Elapsed time: 53150.023 msecs"
;= nil
@agarman
Copy link

agarman commented May 6, 2014

user> (def m {:a 1 :b 2 :c 3 :d 4 :e 5 :f 6 :g 7 :h 8 :i 9 :j 10})

'user/m

user> (use 'criterium.core)
nil
user> (defrecord MyTest [a b c d e f g h i j])
user.MyTest
user>
user> (bench (new MyTest 1 2 3 4 5 6 7 8 9 0))
WARNING: Final GC required 3.657448744144802 % of runtime
Evaluation count : 3180329100 in 60 samples of 53005485 calls.
Execution time mean : 16.754189 ns
Execution time std-deviation : 1.236156 ns
Execution time lower quantile : 14.802149 ns ( 2.5%)
Execution time upper quantile : 19.393579 ns (97.5%)
Overhead used : 2.372168 ns

Found 6 outliers in 60 samples (10.0000 %)
low-severe 6 (10.0000 %)
Variance from outliers : 55.1306 % Variance is severely inflated by outliers
nil
user> (bench (map->MyTest m))
Evaluation count : 12939000 in 60 samples of 215650 calls.
Execution time mean : 4.926109 µs
Execution time std-deviation : 354.458506 ns
Execution time lower quantile : 4.497493 µs ( 2.5%)
Execution time upper quantile : 5.797581 µs (97.5%)
Overhead used : 2.372168 ns

Found 3 outliers in 60 samples (5.0000 %)
low-severe 3 (5.0000 %)
Variance from outliers : 53.4785 % Variance is severely inflated by outliers
nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment