Guest User

Untitled

a guest
May 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. require "benchmark"
  2.  
  3. reps = 5_000_000
  4. str = "1"
  5.  
  6. Benchmark.bm do |b|
  7.  
  8. b.report("comparing string: ") do
  9. reps.times {
  10. str == "1"
  11. }
  12. end
  13.  
  14. b.report("casting string: ") do
  15. reps.times {
  16. str.to_i == 1
  17. }
  18. end
  19.  
  20. end
  21.  
  22. __END__
  23.  
  24.       user     system      total        real
  25. comparing string:   1.480000   0.000000   1.480000 (  1.494659)
  26. casting string:     1.930000   0.010000   1.940000 (  1.949158)
Add Comment
Please, Sign In to add comment