Created
August 31, 2009 20:57
-
-
Save outoftime/178707 to your computer and use it in GitHub Desktop.
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' | |
PATTERN = /@@@(.*?)@@@/ | |
TIMES = 1_000 | |
string = 'one @@@two@@@ three' * 1000 | |
Benchmark.bm(10) do |benchmark| | |
benchmark.report('global') do | |
TIMES.times do | |
string.gsub(PATTERN) { Regexp.last_match(1).reverse } | |
end | |
end | |
benchmark.report('local') do | |
TIMES.times do | |
string.gsub(PATTERN) { |match| PATTERN.match(match)[1].reverse } | |
end | |
end | |
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
user system total real | |
global 2.530000 0.000000 2.530000 ( 2.604000) | |
local 4.150000 0.020000 4.170000 ( 4.225362) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment