public
Last active

compare loop, recursive calls, recurring calls

  • Download Gist
loop-recursive-tco-comparison.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
(use 'criterium.core)
 
(defn looping [n]
(loop [i n]
(when (< 1 i)
(recur (dec i)))))
 
(defn recursive [n]
(when (< 1 n) (recursive (dec n))))
 
(defn tco [n]
(when (< 1 n) (recur (dec n))))
 
(defn tco2
([] (tco2 5))
([n] (when (< 1 n) (recur (dec n)))))
 
(defn bmark [n]
(println "looping" n)
(bench (looping n) :verbose)
(println "recursive" n)
(bench (recursive n) :verbose)
(println "tco" n)
(bench (tco n) :verbose)
(println "tco2" n)
(bench (tco2 n) :verbose))
 
(defn bmarks []
(bmark 10)
(bmark 1000))
results.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
(xampl.core/bmarks)
looping 10
x86_64 Mac OS X 10.6.6 8 cpu(s)
Java HotSpot(TM) 64-Bit Server VM 17.1-b03-307
Runtime arguments: -Dfile.encoding=UTF-8
Evaluation count : 780043500
Execution time mean : 78.084013 ns 95.0% CI: (78.070892 ns, 78.093285 ns)
Execution time std-deviation : 4.832753 us 95.0% CI: (4.782522 us, 4.883957 us)
 
Found 5 outliers in 60 samples (8.3333 %)
low-severe 3 (5.0000 %)
low-mild 2 (3.3333 %)
Variance from outliers : 6.2739 % Variance is slightly inflated by outliers
 
 
recursive 10
x86_64 Mac OS X 10.6.6 8 cpu(s)
Java HotSpot(TM) 64-Bit Server VM 17.1-b03-307
Runtime arguments: -Dfile.encoding=UTF-8
Evaluation count : 339902040
Execution time mean : 182.255031 ns 95.0% CI: (182.220704 ns, 182.283222 ns)
Execution time std-deviation : 8.083124 us 95.0% CI: (7.949713 us, 8.238344 us)
 
Found 4 outliers in 60 samples (6.6667 %)
low-severe 2 (3.3333 %)
low-mild 2 (3.3333 %)
Variance from outliers : 7.8125 % Variance is slightly inflated by outliers
 
 
 
tco 10
x86_64 Mac OS X 10.6.6 8 cpu(s)
Java HotSpot(TM) 64-Bit Server VM 17.1-b03-307
Runtime arguments: -Dfile.encoding=UTF-8
Evaluation count : 377653680
Execution time mean : 160.908237 ns 95.0% CI: (160.882899 ns, 160.928526 ns)
Execution time std-deviation : 5.652590 us 95.0% CI: (5.592985 us, 5.726846 us)
 
Found 2 outliers in 60 samples (3.3333 %)
low-severe 1 (1.6667 %)
low-mild 1 (1.6667 %)
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers
 
 
 
tco2 10
x86_64 Mac OS X 10.6.6 8 cpu(s)
Java HotSpot(TM) 64-Bit Server VM 17.1-b03-307
Runtime arguments: -Dfile.encoding=UTF-8
Evaluation count : 376112760
Execution time mean : 158.737037 ns 95.0% CI: (158.725460 ns, 158.748836 ns)
Execution time std-deviation : 3.775872 us 95.0% CI: (3.748230 us, 3.807094 us)
 
Found 2 outliers in 60 samples (3.3333 %)
low-severe 1 (1.6667 %)
low-mild 1 (1.6667 %)
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers
 
 
 
looping 1000
x86_64 Mac OS X 10.6.6 8 cpu(s)
Java HotSpot(TM) 64-Bit Server VM 17.1-b03-307
Runtime arguments: -Dfile.encoding=UTF-8
Evaluation count : 5890560
Execution time mean : 10.354814 us 95.0% CI: (10.354087 us, 10.355570 us)
Execution time std-deviation : 32.552575 us 95.0% CI: (32.326223 us, 32.780239 us)
 
Found 1 outliers in 60 samples (1.6667 %)
low-severe 1 (1.6667 %)
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers
 
 
 
recursive 1000
x86_64 Mac OS X 10.6.6 8 cpu(s)
Java HotSpot(TM) 64-Bit Server VM 17.1-b03-307
Runtime arguments: -Dfile.encoding=UTF-8
Evaluation count : 2782620
Execution time mean : 22.024989 us 95.0% CI: (22.021495 us, 22.027931 us)
Execution time std-deviation : 81.761040 us 95.0% CI: (80.771783 us, 82.584477 us)
 
Found 6 outliers in 60 samples (10.0000 %)
low-severe 4 (6.6667 %)
low-mild 2 (3.3333 %)
Variance from outliers : 6.2771 % Variance is slightly inflated by outliers
 
 
 
tco 1000
x86_64 Mac OS X 10.6.6 8 cpu(s)
Java HotSpot(TM) 64-Bit Server VM 17.1-b03-307
Runtime arguments: -Dfile.encoding=UTF-8
Evaluation count : 3197460
Execution time mean : 19.138813 us 95.0% CI: (19.135399 us, 19.143925 us)
Execution time std-deviation : 96.733389 us 95.0% CI: (95.850014 us, 97.654636 us)
 
Found 1 outliers in 60 samples (1.6667 %)
low-severe 1 (1.6667 %)
Variance from outliers : 9.4567 % Variance is slightly inflated by outliers
 
 
 
tco2 1000
x86_64 Mac OS X 10.6.6 8 cpu(s)
Java HotSpot(TM) 64-Bit Server VM 17.1-b03-307
Runtime arguments: -Dfile.encoding=UTF-8
Evaluation count : 3177360
Execution time mean : 19.117219 us 95.0% CI: (19.115299 us, 19.119325 us)
Execution time std-deviation : 79.230725 us 95.0% CI: (77.715232 us, 80.942765 us)
 
Found 5 outliers in 60 samples (8.3333 %)
low-severe 3 (5.0000 %)
low-mild 2 (3.3333 %)
Variance from outliers : 7.7758 % Variance is slightly inflated by outliers

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.