~ubuntu-branches/ubuntu/utopic/ruby-excon/utopic

« back to all changes in this revision

Viewing changes to benchmarks/strip_newline.rb

  • Committer: Package Import Robot
  • Author(s): Laurent Bigonville
  • Date: 2012-03-07 16:36:21 UTC
  • Revision ID: package-import@ubuntu.com-20120307163621-bztj2b8860dxpzs7
Tags: upstream-0.10.0
ImportĀ upstreamĀ versionĀ 0.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# require 'benchmark'
 
2
 
3
# COUNT = 1_000_000
 
4
# data = "Content-Length: 100\r\n"
 
5
# Benchmark.bmbm(25) do |bench|
 
6
#   bench.report('chomp') do
 
7
#     COUNT.times do
 
8
#       data = "Content-Length: 100\r\n"
 
9
#       data.chomp
 
10
#     end
 
11
#   end
 
12
#   bench.report('chomp!') do
 
13
#     COUNT.times do
 
14
#       data = "Content-Length: 100\r\n"
 
15
#       data.chomp!
 
16
#     end
 
17
#   end
 
18
#   bench.report('chop') do
 
19
#     COUNT.times do
 
20
#       data = "Content-Length: 100\r\n"
 
21
#       data.chop
 
22
#     end
 
23
#   end
 
24
#   bench.report('chop!') do
 
25
#     COUNT.times do
 
26
#       data = "Content-Length: 100\r\n"
 
27
#       data.chop!
 
28
#     end
 
29
#   end
 
30
#   bench.report('strip') do
 
31
#     COUNT.times do
 
32
#       data = "Content-Length: 100\r\n"
 
33
#       data.strip
 
34
#     end
 
35
#   end
 
36
#   bench.report('strip!') do
 
37
#     COUNT.times do
 
38
#       data = "Content-Length: 100\r\n"
 
39
#       data.strip!
 
40
#     end
 
41
#   end
 
42
#   bench.report('index') do
 
43
#     COUNT.times do
 
44
#       data = "Content-Length: 100\r\n"
 
45
#       data[0..-3]
 
46
#     end
 
47
#   end
 
48
# end
 
49
 
 
50
 
 
51
 
 
52
# Rehearsal ------------------------------------------------------------
 
53
# chomp                      0.640000   0.000000   0.640000 (  0.644043)
 
54
# chomp!                     0.530000   0.000000   0.530000 (  0.531415)
 
55
# chop                       0.620000   0.000000   0.620000 (  0.624321)
 
56
# chop!                      0.500000   0.000000   0.500000 (  0.509146)
 
57
# strip                      0.640000   0.000000   0.640000 (  0.638785)
 
58
# strip!                     0.530000   0.000000   0.530000 (  0.532196)
 
59
# index                      0.740000   0.000000   0.740000 (  0.745742)
 
60
# --------------------------------------------------- total: 4.200000sec
 
61
 
62
#                                user     system      total        real
 
63
# chomp                      0.640000   0.010000   0.650000 (  0.647287)
 
64
# chomp!                     0.530000   0.000000   0.530000 (  0.532868)
 
65
# chop                       0.630000   0.000000   0.630000 (  0.628236)
 
66
# chop!                      0.520000   0.000000   0.520000 (  0.522950)
 
67
# strip                      0.640000   0.000000   0.640000 (  0.646328)
 
68
# strip!                     0.520000   0.000000   0.520000 (  0.532715)
 
69
# index                      0.740000   0.010000   0.750000 (  0.771277)
 
70
 
 
71
require 'rubygems'
 
72
require 'tach'
 
73
 
 
74
data = "Content-Length: 100\r\n"
 
75
Tach.meter(1_000_000) do
 
76
  tach('chomp') do
 
77
    data.dup.chomp
 
78
  end
 
79
  tach('chomp!') do
 
80
    data.dup.chomp!
 
81
  end
 
82
  tach('chop') do
 
83
    data.dup.chop
 
84
  end
 
85
  tach('chop!') do
 
86
    data.dup.chop!
 
87
  end
 
88
  tach('strip') do
 
89
    data.dup.strip
 
90
  end
 
91
  tach('strip!') do
 
92
    data.dup.strip!
 
93
  end
 
94
  tach('index') do
 
95
    data.dup[0..-3]
 
96
  end
 
97
end
 
98
 
 
99
# +--------+----------+----------+
 
100
# | tach   | average  | total    |
 
101
# +--------+----------+----------+
 
102
# | chomp  | 1.444547 | 1.444547 |
 
103
# +--------+----------+----------+
 
104
# | chomp! | 1.276813 | 1.276813 |
 
105
# +--------+----------+----------+
 
106
# | chop   | 1.422744 | 1.422744 |
 
107
# +--------+----------+----------+
 
108
# | chop!  | 1.240941 | 1.240941 |
 
109
# +--------+----------+----------+
 
110
# | strip  | 1.444776 | 1.444776 |
 
111
# +--------+----------+----------+
 
112
# | strip! | 1.266459 | 1.266459 |
 
113
# +--------+----------+----------+
 
114
# | index  | 1.557975 | 1.557975 |
 
115
# +--------+----------+----------+
 
 
b'\\ No newline at end of file'