Created
June 6, 2013 03:18
-
-
Save hoguej/5719075 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
require 'parallel' | |
require 'date' | |
require './pieces' # adds pieces function to Array objects | |
@things = [] | |
100_000.times do |i| | |
@things << { name: i.to_s, value: i } | |
end | |
# run 1 | |
@sum = 0 | |
start = Time.now | |
@sum = @things.map{ |t| t[:value] }.reduce(:+) | |
duration = Time.now - start | |
puts @sum | |
puts duration | |
# run 16 times | |
(1..50).each do |procs| | |
(1..50).each do |pieces| | |
start = Time.now | |
@sum = Parallel.map( @things.pieces(pieces), :in_processes => procs ) { |subarray| | |
subarray.map{ |thing| thing[:value] }.reduce(:+) | |
}.reduce(:+) | |
duration = Time.now - start | |
puts "duration:#{duration} procs:#{procs} pieces:#{pieces}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment