Skip to content

Instantly share code, notes, and snippets.

@jkk
Created October 12, 2010 05:08
Show Gist options
  • Select an option

  • Save jkk/621688 to your computer and use it in GitHub Desktop.

Select an option

Save jkk/621688 to your computer and use it in GitHub Desktop.
(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