Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "benchmark"
- reps = 5_000_000
- str = "1"
- Benchmark.bm do |b|
- b.report("comparing string: ") do
- reps.times {
- str == "1"
- }
- end
- b.report("casting string: ") do
- reps.times {
- str.to_i == 1
- }
- end
- end
- __END__
- user system total real
- comparing string: 1.480000 0.000000 1.480000 ( 1.494659)
- casting string: 1.930000 0.010000 1.940000 ( 1.949158)
Add Comment
Please, Sign In to add comment