The JVM optimises sections of code that are frequently executed, so the second expression benefits from the optimisation that happens during the first expression. My guess is that if you were to swap the two expressions around, you'd find that the first expression always takes longer, no matter which way around it is.
Benchmarking libraries like Criterium get around this by "warming up" the JVM with a few practice runs before recording the benchmarks. I'd advise using Criterium over clojure.core/time if you want to benchmark things accurately. - James On 12 July 2014 10:29, Cecil Westerhof <cldwester...@gmail.com> wrote: > I do the following (with range-length 1e8): > (time (let [[t d] (split-with #(< % 12) (range range-length))] > [(count d) (count t)])) > > (time (let [[t d] (split-with #(< % 12) (range range-length))] > (into [] (reverse [(count t) (count d)])))) > > This gives: > "Elapsed time: 68105.338314 msecs" > [99999988 12] > "Elapsed time: 11545.667394 msecs" > [99999988 12] > > So the first expression > takes as six times as long to evaluate. > I understood that this has to do with that in the first case there is > head retention. But I do not understand this. What is happening here? > > > -- > Cecil Westerhof > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.