Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.