Skip to content

Instantly share code, notes, and snippets.

@agibralter
Created August 6, 2010 16:43
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 agibralter/511599 to your computer and use it in GitHub Desktop.
Save agibralter/511599 to your computer and use it in GitHub Desktop.
require 'benchmark'
n = 10
command = "sleep 1"
Benchmark.bm do |x|
x.report do
a = (1..n).collect { Thread.new { `#{command}` } }
a.each { |t| t.join }
end
x.report do
n.times do
`#{command}`
end
end
x.report do
a = (1..n).collect { Thread.new { IO.popen(command) { |io| io.each { |l| l } } } }
a.each { |t| t.join }
end
end
# user system total real
# 0.000000 0.010000 0.060000 ( 1.013273)
# 0.010000 0.000000 0.060000 ( 10.060332)
# 0.000000 0.010000 0.070000 ( 1.013631)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment