Created
October 12, 2010 05:08
-
-
Save jkk/621688 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 pmap-batched [n f xs] | |
| (let [k (int (/ (count xs) n))] | |
| (apply concat (pmap #(doall (map f %)) (partition-all k xs))))) | |
| (defn compute [x] (Thread/sleep 1) x) | |
| (defn compute-all | |
| [batches n] | |
| (pmap-batched batches compute (range n))) | |
| (comment | |
| (time (count (compute-all 1 1000))) | |
| "Elapsed time: 1098.985 msecs" | |
| 1000 | |
| (time (count (compute-all 2 1000))) | |
| "Elapsed time: 548.367 msecs" | |
| 1000 | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment