Guest User

Untitled

a guest
Apr 25th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. require 'benchmark'
  2.  
  3. # Benchmarks for various object operations.
  4. #
  5. # user system total real
  6. # respond_to? 0.300000 0.000000 0.300000 ( 0.301135)
  7. # object_id 0.220000 0.000000 0.220000 ( 0.221668)
  8. # == nil 0.240000 0.000000 0.240000 ( 0.244954)
  9. # nil? 0.220000 0.000000 0.220000 ( 0.221454)
  10. #
  11. Benchmark.bm(20) do |x|
  12.  
  13. n = 1000000
  14. o = Object.new
  15.  
  16. x.report "respond_to?" do
  17. n.times { o.respond_to?(:object_id) }
  18. end
  19.  
  20. x.report "object_id" do
  21. n.times { o.object_id }
  22. end
  23.  
  24. x.report "== nil" do
  25. n.times { o == nil }
  26. end
  27.  
  28. x.report "nil?" do
  29. n.times { o.nil? }
  30. end
  31. end
Add Comment
Please, Sign In to add comment