Why doesn't this Clojure r / fold gearbox provide top priority?

I am wondering why the code below does not provide acceleration in case of r / fold? I don’t understand something about gearboxes?

I run it on a rather slow (albeit with two cores) Ubuntu 12.04 dev box, both through emacs and lein run, each with the same results.

(require '[clojure.core.reducers :as r]) (.. Runtime getRuntime availableProcessors) 

;; 2

 (let [n 80000000 vs #(range n)] (time (reduce + (vs))) (time (r/fold + (vs))) 

"Elapsed time: 26076.434324 ms"
"Elapsed time: 25500.234034 ms"

Thanks.

+5
source share
1 answer

You fold over the section. Parallel folding occurs only on constant vectors and maps right now.

There are also all sorts of reasons why such testing is not inferior to using Criterium , but this is probably a separate discussion. (Some of the reasons are garbage collection, JVM and inlining warming up, funky jvm settings on Emacs and lein by default, in a box and math checking, etc.)

Still wrong for many of the reasons above, but a little more useful comparison is:

 (require '[clojure.core.reducers :as r]) (def v (vec (range 800000))) (dotimes [_ 100] (time (reduce + v))) (dotimes [_ 100] (time (r/fold + v))) 

Stay tuned for the best moments from each of the last two starts.

+7
source

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


All Articles