Skip to content

Instantly share code, notes, and snippets.

@artemave
Last active August 29, 2015 14:04
Show Gist options
  • Save artemave/a1e454a1900f105196e8 to your computer and use it in GitHub Desktop.
Save artemave/a1e454a1900f105196e8 to your computer and use it in GitHub Desktop.
ruby threads and io
require 'benchmark'
def do_stuff
`sleep 0.1`
end
Benchmark.bm(10) do |x|
x.report("sequential") do
10.times { do_stuff }
end
x.report("thread") do
10.times.map do
Thread.new { do_stuff }
end.each(&:join)
end
end
@artemave
Copy link
Author

artemave commented Aug 6, 2014

sequential   0.000000   0.010000   0.040000 (  1.047120)
thread       0.000000   0.010000   0.030000 (  0.113429)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment