Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- # Benchmarks for various object operations.
- #
- # user system total real
- # respond_to? 0.300000 0.000000 0.300000 ( 0.301135)
- # object_id 0.220000 0.000000 0.220000 ( 0.221668)
- # == nil 0.240000 0.000000 0.240000 ( 0.244954)
- # nil? 0.220000 0.000000 0.220000 ( 0.221454)
- #
- Benchmark.bm(20) do |x|
- n = 1000000
- o = Object.new
- x.report "respond_to?" do
- n.times { o.respond_to?(:object_id) }
- end
- x.report "object_id" do
- n.times { o.object_id }
- end
- x.report "== nil" do
- n.times { o == nil }
- end
- x.report "nil?" do
- n.times { o.nil? }
- end
- end
Add Comment
Please, Sign In to add comment