Created
July 12, 2012 15:35
-
-
Save mcansky/3098899 to your computer and use it in GitHub Desktop.
ruby eq strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| N = 10000 | |
| STRING = "cat" | |
| DAT = "cat" | |
| puts "#{STRING} vs #{DAT}" | |
| Benchmark.bmbm do |x| | |
| x.report("==") { N.times { | |
| "cat" == "cat" | |
| } } | |
| x.report("== const") { N.times { | |
| DAT == STRING | |
| } } | |
| x.report("regexp") { N.times { | |
| DAT =~ /^cat$/ | |
| } } | |
| x.report("match") { N.times { | |
| DAT.match STRING | |
| } } | |
| end | |
| # user system total real | |
| # == 0.000000 0.000000 0.000000 ( 0.002899) | |
| # == const 0.010000 0.000000 0.010000 ( 0.001940) | |
| # regexp 0.000000 0.000000 0.000000 ( 0.005289) | |
| # match 0.020000 0.000000 0.020000 ( 0.013405) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment