Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to use a proper benchmarking library; the standard Clojure solution is Hugo Duncan's <a href="https://github.com/hugoduncan/criterium">Criterium</a>.</p> <p>The reason is that code on the JVM starts running in interpreted mode and then eventually gets compiled by the JIT compiler; it's the steady-state behaviour after JIT compilation that you want to benchmark and not behaviour during the profiling stage. This is, however, quite tricky, since the JIT compiler optimizes no-ops away where it can see them, so you need to make sure your code causes side effects that won't be optimized away, but then you still need to run it in a loop to obtain meaningful results etc. -- quick and dirty solutions just don't cut it. (See the <a href="http://www.ellipticgroup.com/html/benchmarkingArticle.html">Elliptic Group, Inc. Java benchmarking article</a>, also linked to by Criterium's README, for an extended discussion of the issues involved.)</p> <p>Cycling the two samples you listed in a vector of length 1000 results in a timing of ~327 µs in a Criterium benchmark on my machine:</p> <pre><code>(require '[criterium.core :as c]) (def v (vec (take 1000 (cycle [[10.0 10.5 9.8 10.1] [10.1 10.8 10.1 10.7]])))) (c/bench (binary-smpls-using v)) WARNING: Final GC required 4.480116525558204 % of runtime Evaluation count : 184320 in 60 samples of 3072 calls. Execution time mean : 327.171892 µs Execution time std-deviation : 3.129050 µs Execution time lower quantile : 322.731261 µs ( 2.5%) Execution time upper quantile : 333.117724 µs (97.5%) Overhead used : 1.900032 ns Found 1 outliers in 60 samples (1.6667 %) low-severe 1 (1.6667 %) Variance from outliers : 1.6389 % Variance is slightly inflated by outliers </code></pre> <p>A really good benchmark would actually involve an interesting dataset (all different samples, preferably coming from the real world).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload