File: headers_split_vs_match.rb

package info (click to toggle)
ruby-excon 0.112.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,232 kB
  • sloc: ruby: 7,855; makefile: 5
file content (34 lines) | stat: -rw-r--r-- 804 bytes parent folder | download | duplicates (7)
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
require 'rubygems'
require 'tach'

data = "Content-Length: 100"
Tach.meter(1_000_000) do
  tach('regex') do
    data.match(/(.*):\s(.*)/)
    header = [$1, $2]
  end
  tach('split') do
    header = data.split(': ', 2)
  end
  tach('split regex') do
    header = data.split(/:\s*/, 2)
  end
end

#  +-------------+----------+
#  | tach        | total    |
#  +-------------+----------+
#  | split regex | 5.940233 |
#  +-------------+----------+
#  | split       | 7.327549 |
#  +-------------+----------+
#  | regex       | 8.736390 |
#  +-------------+----------+

# +-------+----------+----------+
# | tach  | average  | total    |
# +-------+----------+----------+
# | regex | 4.680451 | 4.680451 |
# +-------+----------+----------+
# | split | 4.393218 | 4.393218 |
# +-------+----------+----------+