Readme.md in parallel-0.6.4 vs Readme.md in parallel-0.6.5
- old
+ new
@@ -1,29 +1,39 @@
Run any code in parallel Processes(> use all CPUs) or Threads(> speedup blocking operations).<br/>
Best suited for map-reduce or e.g. parallel downloads/uploads.
Install
=======
- sudo gem install parallel
+```Bash
+gem install parallel
+```
+
Usage
=====
- # 2 CPUs -> work in 2 processes (a,b + c)
- results = Parallel.map(['a','b','c']) do |one_letter|
- expensive_calculation(one_letter)
- end
- # 3 Processes -> finished after 1 run
- results = Parallel.map(['a','b','c'], :in_processes=>3){|one_letter| ... }
+```Ruby
+# 2 CPUs -> work in 2 processes (a,b + c)
+results = Parallel.map(['a','b','c']) do |one_letter|
+ expensive_calculation(one_letter)
+end
- # 3 Threads -> finished after 1 run
- results = Parallel.map(['a','b','c'], :in_threads=>3){|one_letter| ... }
+# 3 Processes -> finished after 1 run
+results = Parallel.map(['a','b','c'], :in_processes=>3){|one_letter| ... }
+# 3 Threads -> finished after 1 run
+results = Parallel.map(['a','b','c'], :in_threads=>3){|one_letter| ... }
+```
+
Same can be done with `each`
- Parallel.each(['a','b','c']){|one_letter| ... }
+```Ruby
+Parallel.each(['a','b','c']){|one_letter| ... }
+```
or `each_with_index` or `map_with_index`
+Processes/Threads are workers, they grab the next piece of work when they finish.
+
### Processes
- Speedup through multiple CPUs
- Speedup for blocking operations
- Protects global data
- Extra memory used ( very low on [REE](http://www.rubyenterpriseedition.com/faq.html) through `copy_on_write_friendly` )
@@ -57,19 +67,20 @@
Parallel.map(User.all) do |user|
raise Parallel::Break # -> stop all execution
end
```
-Processes/Threads are workers, they grab the next piece of work when they finish
-
### Progress / ETA
+```Bash
+gem install ruby-progressbar
+```
+
```Ruby
-require 'progressbar'
-progress = ProgressBar.new("test", 100)
-Parallel.map(1..100, :finish => lambda { |i, item| progress.inc }) { sleep 1 }
-progress.finish
+require 'ruby-progressbar'
+progress = ProgressBar.create(:title => "The Progress", :total => 100)
+Parallel.map(1..100, :finish => lambda { |i, item| progress.increment }) { sleep 1 }
```
Tips
====
- [Benchmark/Test] Disable threading/forking with `:in_threads => 0` or `:in_processes => 0`, great to test performance or to debug parallel issues
@@ -101,6 +112,6 @@
- [Joachim](https://github.com/jmozmoz)
[Michael Grosser](http://grosser.it)<br/>
michael@grosser.it<br/>
License: MIT<br/>
-[![Flattr](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=grosser&url=https://github.com/grosser/parallel&title=parallel&language=en_GB&tags=github&category=software)
+[![Build Status](https://travis-ci.org/grosser/parallel.png)](https://travis-ci.org/grosser/parallel)