Skip to content

Instantly share code, notes, and snippets.

@zakwilson
Created May 28, 2010 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakwilson/416794 to your computer and use it in GitHub Desktop.
Save zakwilson/416794 to your computer and use it in GitHub Desktop.
(defn zpmap [f coll]
(apply concat
(pmap #(doall (map f %))
(partition-all (Math/ceil (/ (count coll)
(float (+ 2 (.availableProcessors
(Runtime/getRuntime))))))
coll))))
; This is intended for a fast f and large coll, where pmap performs poorly.
; It provides a nearly 2x speedup over map on dual-core machines I've tried it on;
; a map operation that took 5.5 seconds takes 3 with zpmap. It's not providing any
; further improvement on a quad-core machine. Changing the above code to partition
; in to only two pieces has little to no effect on the time required to run on a
; quad-core machine, though it does reduce CPU usage from 390% to 200%.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment