Skip to content

Instantly share code, notes, and snippets.

@kindlychung
Last active August 29, 2015 14:20
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 kindlychung/6b1e2afd269cd3c074ae to your computer and use it in GitHub Desktop.
Save kindlychung/6b1e2afd269cd3c074ae to your computer and use it in GitHub Desktop.
(use 'criterium.core)
(defmacro bench-progress [& body]
`(with-progress-reporting
(bench ~@body)))
(defn sum [xs]
(reduce + xs))
(defn array-sum [^ints xs]
(loop [index 0 acc 0]
(if (< index (alength xs))
(recur (unchecked-inc index) (+ acc (aget xs index)))
acc)))
(let [x (range 1e6)
y (int-array x)]
(bench-progress (sum x))
(bench-progress (array-sum y)))
@kindlychung
Copy link
Author

Warming up for JIT optimisations 10000000000 ...
Estimating execution count ...
Sampling ...
Final GC...
Checking GC...
Finding outliers ...
Bootstrapping ...
Checking outlier significance
Evaluation count : 4500 in 60 samples of 75 calls.
Execution time mean : 13.578010 ms
Execution time std-deviation : 773.198360 µs
Execution time lower quantile : 12.405108 ms ( 2.5%)
Execution time upper quantile : 15.128228 ms (97.5%)
Overhead used : 1.820901 ns

Found 1 outliers in 60 samples (1.6667 %)
low-severe 1 (1.6667 %)
Variance from outliers : 41.8253 % Variance is moderately inflated by outliers
Warming up for JIT optimisations 10000000000 ...
compilation occured before 1454 iterations
compilation occured before 5813 iterations
compilation occured before 7266 iterations
Estimating execution count ...
Sampling ...
Final GC...
Checking GC...
Finding outliers ...
Bootstrapping ...
Checking outlier significance
Evaluation count : 49260 in 60 samples of 821 calls.
Execution time mean : 1.244392 ms
Execution time std-deviation : 57.388621 µs
Execution time lower quantile : 1.183661 ms ( 2.5%)
Execution time upper quantile : 1.383249 ms (97.5%)
Overhead used : 1.820901 ns

Found 7 outliers in 60 samples (11.6667 %)
low-severe 5 (8.3333 %)
low-mild 2 (3.3333 %)
Variance from outliers : 31.9729 % Variance is moderately inflated by outliers

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