Skip to content

Instantly share code, notes, and snippets.

@rbxbx
Created June 2, 2010 02:34
Show Gist options
  • Save rbxbx/421840 to your computer and use it in GitHub Desktop.
Save rbxbx/421840 to your computer and use it in GitHub Desktop.
require 'peach'
[1,2,3,4].peach{ |n| n + 1 } #Spawns 4 threads
[1,2,3,4].pmap{ |x| f(x) } #Spawns 4 threads, returns => [f(1),f(2),f(3),f(4)]
[1,2,3,4].pselect{ |x| x > 2 } #Spawns 4 threads, returns => [3,4]
@paulodelgado
Copy link

reading the blog post, shouldn't that be a pselect in line 5?

@rbxbx
Copy link
Author

rbxbx commented Jun 2, 2010

you're correct!
Fixed, thanks.

@devn
Copy link

devn commented Nov 29, 2010

I want to know more about this. How does it handle "unbalanced" CPU loads. For instance, one operation takes 30 seconds, and the rest all take 2. Also, how does it glean enough knowledge to know the "correct" number of threads for your block? Clojure has a really sexy pmap, preduce, etc. coming in 1.3 and after learning about how it actually I'm skeptical of this library and its effectiveness. How do these pmethods behave when they're thrown tasks which require variable lengths of time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment