clojureleiningenread-eval-print-looplighttable

Difference between time of completion in LightTable and lein REPL


I'm facing strange difference within time of completion between lein repl and LightTable Instarepl(LTIR). For example the following code:

(defn lazy-primes
  ([] (cons 2 (lazy-seq (lazy-primes 3  [ 2 ]))))
  ([current calculated-primes]
   (loop [ [first-prime & rest-primes] calculated-primes]
     (if (> (* first-prime first-prime) current)
       (cons current (lazy-seq (lazy-primes
                                (inc current)
                                (conj calculated-primes current))))
       (if (= 0 (mod current first-prime))
         (lazy-seq (lazy-primes (inc current) calculated-primes))
         (recur rest-primes))))))

(time (last (take 10001 (lazy-primes))))

in my LTIR it took:

"Elapsed time: 4535.442412 msecs"

but in lein repl:

"Elapsed time: 431.378074 msecs"

About tenfold difference!

So, here is the question - why so big difference?

Clojure version for LTIR and lein repl is 1.7.0

This code isn't mine, it's from codereview


Solution

  • using time like this makes for a very poor "micro benchmark" because the JVM "warm's up" a function which can have a large impact on running time, along with all the other problems associated with small data sets.

    There is just too many ways this benchmark can be affected by enviromental differences that will change over even short timescales to answer directly. Hugo Duncan wrote a small library for accurately doing this kind of micro benchmark and you will likely get very different results from running this same code on both platforms using it.