Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
$ 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 =
f_result =*set).collect{|x| x**2}
finish =
puts "Forque Benchmark: #{finish-start}"
start =
p_result =, :in_processes => 4){|x| x**2}
finish =
puts "Parallel Benchmark: #{finish-start}"
start =
s_result ={|x| x**2}
finish =
puts "Serial Benchmark: #{finish-start}"
unless f_result == p_result and f_result == s_result
puts "Results not equal!"
puts "== Few Large Jobs Benchmark =="
set = [1]*100
start =*set).collect{|x| sleep(x) }
finish =
puts "Forque Benchmark: #{finish-start}"
start =, :in_processes => 4){|x| sleep(x) }
finish =
puts "Parallel Benchmark: #{finish-start}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment