Skip to content

Instantly share code, notes, and snippets.

@headius
Created April 4, 2013 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/5315475 to your computer and use it in GitHub Desktop.
Save headius/5315475 to your computer and use it in GitHub Desktop.
Simple bench of the overhead of nonblocking calls that would block
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment