public
Created

  • Download Gist
output.txt
1 2 3 4 5 6 7 8
$ ruby parallel_bench.rb
== Many Small Jobs Benchmark ==
Forque Benchmark: 0.097953
Parallel Benchmark: 10.233478
Serial Benchmark: 0.000956
== Few Large Jobs Benchmark ==
Forque Benchmark: 25.104783
Parallel Benchmark: 26.984219
parallel_forque_bench.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
require 'rubygems'
require 'parallel'
require 'forque/forque'
 
set = (1..500).collect
 
puts "== Many Small Jobs Benchmark =="
 
start = Time.now
f_result = Forque.new(*set).collect{|x| x**2}
finish = Time.now
 
puts "Forque Benchmark: #{finish-start}"
 
 
start = Time.now
p_result = Parallel.map(set, :in_processes => 4){|x| x**2}
finish = Time.now
 
puts "Parallel Benchmark: #{finish-start}"
 
start = Time.now
s_result = set.map{|x| x**2}
finish = Time.now
 
puts "Serial Benchmark: #{finish-start}"
 
f_result.sort!
p_result.sort!
s_result.sort!
unless f_result == p_result and f_result == s_result
puts "Results not equal!"
end
 
puts "== Few Large Jobs Benchmark =="
 
set = [1]*100
 
start = Time.now
Forque.new(*set).collect{|x| sleep(x) }
finish = Time.now
 
puts "Forque Benchmark: #{finish-start}"
 
 
start = Time.now
Parallel.map(set, :in_processes => 4){|x| sleep(x) }
finish = Time.now
 
puts "Parallel Benchmark: #{finish-start}"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.