Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 3db57a929a
Fetching contributors…

Cannot retrieve contributors at this time

file 51 lines (40 sloc) 1.202 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

require 'rubygems'
require 'rbench'

TIMES = 1_000

short = lambda { |i| %r{^foo#{i}} }
medium = lambda { |i| %r{(foo|bar)#{i}} }
long = lambda { |i| %r{(cpu,|load,shortterm$|memory,|disk,[^,]+,disk_time,),#{i}} }

HUNDRED_SHORT = (1..100).to_a.map(&short)
HUNDRED_MEDIUM = (1..100).to_a.map(&medium)
HUNDRED_LONG = (1..100).to_a.map(&long)

THOUSAND_SHORT = (1..1000).to_a.map(&short)
THOUSAND_MEDIUM = (1..1000).to_a.map(&short)
THOUSAND_LONG = (1..1000).to_a.map(&short)

RBench.run(TIMES) do

  column :times
  column :short, :title => "^foo42"
  column :medium, :title => "(foo|bar)42"
  column :long, :title => "(cpu,|load,shortterm$|memory,|disk,[^,]+,disk_time,)42"


  report "100 regexps" do
    short do
      HUNDRED_SHORT.select { |re| "foo42" =~ re }
    end
    medium do
      HUNDRED_MEDIUM.select { |re| "asdfbar42" =~ re }
    end
    long do
      HUNDRED_LONG.select { |re| "apollo,memory,42" }
    end
  end

  report "1K regexps" do
    short do
      THOUSAND_SHORT.select { |re| "foo42" =~ re }
    end
    medium do
      THOUSAND_MEDIUM.select { |re| "asdfbar42" =~ re }
    end
    long do
      THOUSAND_LONG.select { |re| "apollo,memory,42" }
    end
  end

end
Something went wrong with that request. Please try again.