Created
July 22, 2013 17:48
-
-
Save slawosz/6055961 to your computer and use it in GitHub Desktop.
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
➜ threads cat read_nonblock.rb | |
require 'benchmark' | |
result = Benchmark.measure do | |
(1..4).map { |i| | |
f = File.open("tmp#{i}.txt", 'w') | |
1.upto(100_000) do | |
f.write_nonblock('a' * 100) rescue nil | |
end | |
} | |
end | |
result2 = Benchmark.measure do | |
(1..4).map { |i| | |
Thread.new do | |
f = File.open("tmp#{i}.txt", 'w') | |
1.upto(100_000) do | |
f.write_nonblock('a' * 100) rescue nil | |
end | |
end | |
}.each(&:join) | |
end | |
puts 'non' | |
puts result | |
puts 'threaded' | |
puts result2 | |
➜ threads cat read_block.rb | |
require 'benchmark' | |
result2 = Benchmark.measure do | |
(1..8).map { |i| | |
f = File.open("tmp#{i}.txt", 'w') | |
1.upto(100_000) do | |
f.write('a' * 100) rescue nil | |
end | |
} | |
end | |
result = Benchmark.measure do | |
(1..8).map { |i| | |
Thread.new do | |
f = File.open("tmp#{i}.txt", 'w') | |
1.upto(100_000) do | |
f.write('a' * 100) rescue nil | |
end | |
end | |
}.each(&:join) | |
end | |
puts 'Threaded:' | |
puts result | |
puts 'Non threaded 2:' | |
puts result2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment