Skip to content

Instantly share code, notes, and snippets.

@ngauthier
Created October 13, 2010 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngauthier/624566 to your computer and use it in GitHub Desktop.
Save ngauthier/624566 to your computer and use it in GitHub Desktop.
$ 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
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}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment