File: regexp.rb

package info (click to toggle)
ruby-mustermann19 0.4.3%2Bgit20160621-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 756 kB
  • ctags: 445
  • sloc: ruby: 7,197; makefile: 3
file content (21 lines) | stat: -rw-r--r-- 508 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'benchmark'

puts " atomic vs normal segments ".center(52, '=')

types = {
  normal: /\A\/(?:a|%61)\/(?<b>[^\/\?#]+)(?:\/(?<c>[^\/\?#]+))?\Z/,
  atomic: /\A\/(?:a|%61)\/(?<b>(?>[^\/\?#]+))(?:\/(?<c>(?>[^\/\?#]+)))?\Z/
}

Benchmark.bmbm do |x|
  types.each do |name, regexp|
    string = "/a/" << ?a * 10000 << "/" << ?a * 5000
    fail unless regexp.match(string)
    string << "/"
    fail if regexp.match(string)

    x.report name.to_s do
      100.times { regexp.match(string) }
    end
  end
end