Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Last active December 10, 2020 12:22
Show Gist options
  • Save dchelimsky/fa2290373430252ae367 to your computer and use it in GitHub Desktop.
Save dchelimsky/fa2290373430252ae367 to your computer and use it in GitHub Desktop.
(ns multi-arity-v-varargs.core
(:require [criterium.core :refer [quick-bench]])
(:gen-class))
(defn varargs [arg1 & [arg2 arg3]]
42)
(defn multi-arity
([arg1] 42)
([arg1 arg2] 42)
([arg1 arg2 arg3] 42))
(defn multi-arity-call-through
([arg1] (multi-arity-call-through arg1 10))
([arg1 arg2] (multi-arity-call-through arg1 arg2 20))
([arg1 arg2 arg3] 42))
(defn -main [& args]
(println "Multi 1 arg")
(quick-bench
(multi-arity 0))
(println "Multi 3 args")
(quick-bench
(multi-arity 0 1 2))
(println "Multi 1 arg w/ call through")
(quick-bench
(multi-arity-call-through 0))
(println "Multi 3 args w/ call through")
(quick-bench
(multi-arity-call-through 0 1 2))
(println "Varargs 1 arg")
(quick-bench
(varargs 0))
(println "Varargs 3 args")
(quick-bench
(varargs 0 1 2))
(println "done"))
;; result
Multi 1 arg
WARNING: Final GC required 15.82548498839825 % of runtime
Evaluation count : 170355870 in 6 samples of 28392645 calls.
Execution time mean : 1.902084 ns
Execution time std-deviation : 0.158085 ns
Execution time lower quantile : 1.773372 ns ( 2.5%)
Execution time upper quantile : 2.152973 ns (97.5%)
Overhead used : 1.660097 ns
Found 1 outliers in 6 samples (16.6667 %)
low-severe 1 (16.6667 %)
Variance from outliers : 15.6194 % Variance is moderately inflated by outliers
Multi 3 args
WARNING: Final GC required 8.75622231525542 % of runtime
Evaluation count : 93219132 in 6 samples of 15536522 calls.
Execution time mean : 5.162136 ns
Execution time std-deviation : 0.292710 ns
Execution time lower quantile : 4.694374 ns ( 2.5%)
Execution time upper quantile : 5.485146 ns (97.5%)
Overhead used : 1.660097 ns
Found 1 outliers in 6 samples (16.6667 %)
low-severe 1 (16.6667 %)
Variance from outliers : 14.4168 % Variance is moderately inflated by outliers
Multi 1 arg w/ call through
WARNING: Final GC required 6.244795387173103 % of runtime
Evaluation count : 81485304 in 6 samples of 13580884 calls.
Execution time mean : 6.157217 ns
Execution time std-deviation : 0.365094 ns
Execution time lower quantile : 5.843331 ns ( 2.5%)
Execution time upper quantile : 6.698702 ns (97.5%)
Overhead used : 1.660097 ns
Multi 3 args w/ call through
WARNING: Final GC required 7.272528754417497 % of runtime
Evaluation count : 89955096 in 6 samples of 14992516 calls.
Execution time mean : 4.992798 ns
Execution time std-deviation : 0.355421 ns
Execution time lower quantile : 4.582407 ns ( 2.5%)
Execution time upper quantile : 5.463476 ns (97.5%)
Overhead used : 1.660097 ns
Varargs 1 arg
WARNING: Final GC required 6.391971260977754 % of runtime
Evaluation count : 58522680 in 6 samples of 9753780 calls.
Execution time mean : 9.198122 ns
Execution time std-deviation : 0.493394 ns
Execution time lower quantile : 8.538598 ns ( 2.5%)
Execution time upper quantile : 9.678353 ns (97.5%)
Overhead used : 1.660097 ns
Varargs 3 args
WARNING: Final GC required 6.138204591895891 % of runtime
Evaluation count : 2182842 in 6 samples of 363807 calls.
Execution time mean : 275.481888 ns
Execution time std-deviation : 15.743545 ns
Execution time lower quantile : 258.932920 ns ( 2.5%)
Execution time upper quantile : 290.964401 ns (97.5%)
Overhead used : 1.660097 ns
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment