Last active
August 29, 2015 14:04
-
-
Save artemave/a1e454a1900f105196e8 to your computer and use it in GitHub Desktop.
ruby threads and io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Author
artemave
commented
Aug 6, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment