Created
July 27, 2011 14:44
-
-
Save Watson1978/1109499 to your computer and use it in GitHub Desktop.
Benchmark : MacRuby's Regexp vs Cocoa's
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' | |
Benchmark.bm(5) do |x| | |
str = "MacRuby is an implementation of Ruby 1.9" | |
x.report "Ruby" { | |
str.match(/([^ ]+)/) | |
#p $1 | |
} | |
framework 'Foundation' | |
x.report "Cocoa" { | |
error = Pointer.new(:object) | |
regexp = | |
NSRegularExpression.regularExpressionWithPattern("([^ ]+)", | |
options:NSRegularExpressionCaseInsensitive, | |
error:error) | |
match = | |
regexp.firstMatchInString(str, | |
options:NSMatchingReportProgress, | |
range:NSMakeRange(0, str.length)) | |
#p str.substringWithRange(match.rangeAtIndex(0)) | |
} | |
end |
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
$ macruby bm_regexp.rb | |
user system total real | |
Ruby 0.000000 0.000000 0.000000 ( 0.000072) | |
Cocoa 0.010000 0.000000 0.010000 ( 0.012324) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment