Skip to content

Instantly share code, notes, and snippets.

@cgrand
Last active August 29, 2015 14:06
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 cgrand/f9b9b6300cecbaf91d18 to your computer and use it in GitHub Desktop.
Save cgrand/f9b9b6300cecbaf91d18 to your computer and use it in GitHub Desktop.
package base;
public class GCD {
public static long gcd(long a, long b) {
while (a != b) {
if (a < b) b -= a;
else a -= b;
}
return a;
}
}
=> (crit/quick-bench (base.GCD/gcd 65678 5675684))
WARNING: Final GC required 29.3459828081481 % of runtime
Evaluation count : 3690984 in 6 samples of 615164 calls.
Execution time mean : 321,007455 ns
Execution time std-deviation : 245,404954 ns
Execution time lower quantile : 151,285235 ns ( 2,5%)
Execution time upper quantile : 633,579387 ns (97,5%)
Overhead used : 2,173030 ns
nil
=> (crit/quick-bench (-fast-gcd 65678 5675684))
WARNING: Final GC required 182.39447315166092 % of runtime
Evaluation count : 3743442 in 6 samples of 623907 calls.
Execution time mean : 165,832780 ns
Execution time std-deviation : 5,079956 ns
Execution time lower quantile : 158,575288 ns ( 2,5%)
Execution time upper quantile : 171,282710 ns (97,5%)
Overhead used : 2,173030 ns
nil
=> (defn -not-so-fast-gcd ^long [^long a ^long b]
(if (== a b)
a
(if (> a b)
(recur (- a b) b)
(recur a (- b a)))))
#'user/-not-so-fast-gcd
=> (crit/quick-bench (-not-so-fast-gcd 65678 5675684))
WARNING: Final GC required 70.41637325295699 % of runtime
Evaluation count : 2502234 in 6 samples of 417039 calls.
Execution time mean : 260,302822 ns
Execution time std-deviation : 35,278050 ns
Execution time lower quantile : 234,711291 ns ( 2,5%)
Execution time upper quantile : 304,476349 ns (97,5%)
Overhead used : 2,173030 ns
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment