Created
May 28, 2010 05:24
-
-
Save zakwilson/416794 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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