public
Created

Simple bench of the overhead of nonblocking calls that would block

  • Download Gist
nonblock_bench.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
require 'benchmark'
 
inn, out = IO.pipe
 
5.times do
puts Benchmark.measure {
100_000.times do
begin
inn.read_nonblock(1000)
rescue IO::WaitReadable
end
end
}
end
 
__END__
 
Results without and with patch for #6154
 
$ ./ruby -I lib:ext:. nonblock_bench.rb
0.940000 0.170000 1.110000 ( 1.113261)
0.940000 0.170000 1.110000 ( 1.104994)
0.940000 0.160000 1.100000 ( 1.108880)
0.950000 0.170000 1.120000 ( 1.107059)
0.970000 0.170000 1.140000 ( 1.148363)
$ ./ruby -I lib:ext:.:ext/socket nonblock_bench.rb
0.660000 0.140000 0.800000 ( 0.808189)
0.680000 0.150000 0.830000 ( 0.814997)
0.670000 0.140000 0.810000 ( 0.811901)
0.670000 0.140000 0.810000 ( 0.804447)
0.670000 0.140000 0.810000 ( 0.817231)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.