Clojure Transient Example - No Significant Acceleration

I copied the code from:

http://clojure.org/transients

but my results are significantly different from what was published.

(defn vrange [n] (loop [i 0 v []] (if (< in) (recur (inc i) (conj vi)) v))) (defn vrange2 [n] (loop [i 0 v (transient [])] (if (< in) (recur (inc i) (conj! vi)) (persistent! v)))) (quick-bench (def v (vrange 1000000))) "Elapsed time: 459.59 msecs" (quick-bench (def v2 (vrange2 1000000))) "Elapsed time: 379.85 msecs" 

Is this a bit of an acceleration, but not like an 8x increase in the docs example?

Running java in server mode changes the history, but still nothing like documents.

 (quick-bench (def v (vrange 1000000))) "Elapsed time: 121.14 msecs" (quick-bench (def v2 (vrange2 1000000))) "Elapsed time: 75.15 msecs" 

Have the persistent implementations improved after reporting transients here: http://clojure.org/transients ?

What other factors can affect the lack of transient stimulus?

I am using java version of OpenJDK 1.7 on ubuntu 12.04. Maybe this is much slower than the (supposed) version of Hotspot 1.6 used in the documents? But doesn't that mean that BOTH tests should be slower with some constant with the same gap?

+5
source share
1 answer

Your results are consistent with my experience with transients. I have used them very little, and I usually see a 2x performance improvement.

I tried this on Ubuntu 12.04, OpenJDK 1.7 with Clojure 1.6.0 and 1.7.0-alpha3. I get 2x transient performance, slightly less than 3x that I get on OSX with 1.8 Oracle jvm.

Also the above page since Clojure 1.2, and collection performance has improved significantly since then. I tried the experiment with 1.2, but Criterium does not work with it, so I had to use the time, as on this page. Obviously, the results vary widely (from 2x to 8x). I suspect that the example in the documentation may have been cherry.

+1
source

Source: https://habr.com/ru/post/1207278/


All Articles