Last active
December 20, 2016 00:31
-
-
Save mykoweb/634172347c7480a50edb3ce37b1ab418 to your computer and use it in GitHub Desktop.
2016-12-15-io-bound-threads-in-ruby
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' | |
@threads = [] | |
Benchmark.bm(14) do |x| | |
x.report('no-threads') do | |
8.times do | |
tmp_array = [] | |
10_000_000.times { |n| tmp_array << n } | |
end | |
end | |
x.report('with-threads') do | |
8.times do | |
@threads << Thread.new do | |
tmp_array = [] | |
10_000_000.times { |n| tmp_array << n } | |
end | |
end | |
@threads.each(&:join) | |
end | |
end |
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
user system total real | |
no-threads 4.180000 0.280000 4.460000 ( 4.500382) | |
with-threads 4.290000 0.270000 4.560000 ( 4.647151) |
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 'faraday' | |
require 'benchmark' | |
@conn = Faraday.new(url: 'https://www.google.com') | |
@threads = [] | |
Benchmark.bm(14) do |x| | |
x.report('no-threads') do | |
8.times { @conn.get } | |
end | |
x.report('with-threads') do | |
8.times do | |
@threads << Thread.new { @conn.get } | |
end | |
@threads.each(&:join) | |
end | |
end |
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
user system total real | |
no-threads 0.100000 0.020000 0.120000 ( 3.201572) | |
with-threads 0.110000 0.010000 0.120000 ( 0.580500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment