mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Performance is increased by doing this:
require 'benchmark'
require 'tempfile'
n = 50000
test = File.expand_path(Tempfile.new('foo'))
Benchmark.bm(20) do |x|
x.report("Regex:") do
n.times { test =~ /\A#{test}/ }
end
x.report("String#start_with?:") do
n.times { test =~ test.start_with?(test) }
end
end
Benchmark result:
user system total real
Regex: 0.440000 0.010000 0.450000 ( 0.447357)
String#start_with?: 0.000000 0.000000 0.000000 ( 0.006313)