File: simple_vs_sinatra.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 (23 lines) | stat: -rw-r--r-- 854 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$:.unshift File.expand_path('../lib', File.dirname(__FILE__))

require 'benchmark'
require 'mustermann/simple'
require 'mustermann/sinatra'

[Mustermann::Simple, Mustermann::Sinatra].each do |klass|
  puts "", " #{klass} ".center(64, '=')
  Benchmark.bmbm do |x|
    no_capture = klass.new("/simple")
    x.report("no captures, match") { 1_000.times { no_capture.match('/simple') } }
    x.report("no captures, miss") { 1_000.times { no_capture.match('/miss') } }

    simple = klass.new("/:name")
    x.report("simple, match") { 1_000.times { simple.match('/simple').captures } }
    x.report("simple, miss") { 1_000.times { simple.match('/mi/ss') } }

    splat = klass.new("/*")
    x.report("splat, match") { 1_000.times { splat.match("/a/b/c").captures } }
    x.report("splat, miss") { 1_000.times { splat.match("/a/b/c.miss") } }
  end
  puts
end