Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 181 lines (171 sloc) 5.003 kb
d9e6258 @dchelimsky add benchmark showing improvement by moving from DSL to classes
dchelimsky authored
1 require 'benchmark'
2 require 'rspec/expectations'
3
4 include RSpec::Expectations
5 include RSpec::Matchers
6
7 RSpec::Matchers.define :eq_using_dsl do |expected|
8 match do |actual|
9 actual == expected
10 end
11 end
12
13 n = 1000
14
15 puts "3 runs of #{n} times for each example running #{RUBY_ENGINE}/#{RUBY_VERSION}"
16
17 puts "passing examples: 5.should eq(5)"
18 puts "* using the DSL"
19 Benchmark.benchmark do |bm|
20 3.times do
21 bm.report do
22 n.times do
23 5.should eq_using_dsl(5)
24 end
25 end
26 end
27 end
28
29 puts
30 puts "* using a class"
31 Benchmark.benchmark do |bm|
32 3.times do
33 bm.report do
34 n.times do
35 5.should eq(5)
36 end
37 end
38 end
39 end
40
41 puts
42 puts "failing examples: 5.should eq(3)"
43 puts "* using the DSL"
44 Benchmark.benchmark do |bm|
45 3.times do
46 bm.report do
47 n.times do
48 5.should eq_using_dsl(3) rescue nil
49 end
50 end
51 end
52 end
53
54 puts
55 puts "* using a class"
56 Benchmark.benchmark do |bm|
57 3.times do
58 bm.report do
59 n.times do
60 5.should eq(3) rescue nil
61 end
62 end
63 end
64 end
65
66 # 3 runs of 1000 times for each example running ruby/1.8.7
67 # passing examples: 5.should eq(5)
68 # * using the DSL
69 # 0.340000 0.000000 0.340000 ( 0.342052)
70 # 0.330000 0.010000 0.340000 ( 0.340618)
71 # 0.340000 0.000000 0.340000 ( 0.339149)
72 #
73 # * using a class
74 # 0.000000 0.000000 0.000000 ( 0.003762)
75 # 0.010000 0.000000 0.010000 ( 0.004192)
76 # 0.000000 0.000000 0.000000 ( 0.003791)
77 #
78 # failing examples: 5.should eq(3)
79 # * using the DSL
80 # 0.380000 0.000000 0.380000 ( 0.384415)
81 # 0.380000 0.010000 0.390000 ( 0.381604)
82 # 0.370000 0.000000 0.370000 ( 0.380255)
83 #
84 # * using a class
85 # 0.040000 0.000000 0.040000 ( 0.034528)
86 # 0.030000 0.000000 0.030000 ( 0.032021)
87 # 0.060000 0.010000 0.070000 ( 0.067579)
88 #
89 # 3 runs of 1000 times for each example running ruby/1.9.2
90 # passing examples: 5.should eq(5)
91 # * using the DSL
92 # 0.250000 0.010000 0.260000 ( 0.249692)
93 # 0.250000 0.000000 0.250000 ( 0.253856)
94 # 0.230000 0.000000 0.230000 ( 0.232787)
95 #
96 # * using a class
97 # 0.000000 0.000000 0.000000 ( 0.001069)
98 # 0.000000 0.000000 0.000000 ( 0.001041)
99 # 0.000000 0.000000 0.000000 ( 0.001023)
100 #
101 # failing examples: 5.should eq(3)
102 # * using the DSL
103 # 0.370000 0.000000 0.370000 ( 0.377139)
104 # 0.360000 0.010000 0.370000 ( 0.358379)
105 # 0.370000 0.000000 0.370000 ( 0.373795)
106 #
107 # * using a class
108 # 0.060000 0.010000 0.070000 ( 0.073325)
109 # 0.050000 0.000000 0.050000 ( 0.053562)
110 # 0.070000 0.000000 0.070000 ( 0.075382)
111 #
112 # 3 runs of 1000 times for each example running ruby/1.9.3
113 # passing examples: 5.should eq(5)
114 # * using the DSL
115 # 0.210000 0.000000 0.210000 ( 0.219539)
116 # 0.220000 0.010000 0.230000 ( 0.217905)
117 # 0.220000 0.000000 0.220000 ( 0.219657)
118 #
119 # * using a class
120 # 0.000000 0.000000 0.000000 ( 0.001054)
121 # 0.000000 0.000000 0.000000 ( 0.001048)
122 # 0.000000 0.000000 0.000000 ( 0.001035)
123 #
124 # failing examples: 5.should eq(3)
125 # * using the DSL
126 # 0.350000 0.000000 0.350000 ( 0.351742)
127 # 0.360000 0.000000 0.360000 ( 0.362456)
128 # 0.340000 0.010000 0.350000 ( 0.351098)
129 #
130 # * using a class
131 # 0.080000 0.000000 0.080000 ( 0.079964)
132 # 0.080000 0.000000 0.080000 ( 0.076579)
133 # 0.070000 0.000000 0.070000 ( 0.080587)
134 #
135 # 3 runs of 1000 times for each example running rbx/1.8.7
136 # passing examples: 5.should eq(5)
137 # * using the DSL
138 # 1.926107 0.009784 1.935891 ( 1.629354)
139 # 0.583860 0.004390 0.588250 ( 0.580396)
140 # 0.868571 0.003510 0.872081 ( 0.796644)
141 #
142 # * using a class
143 # 0.002652 0.000013 0.002665 ( 0.002679)
144 # 0.001845 0.000016 0.001861 ( 0.001848)
145 # 0.002656 0.000010 0.002666 ( 0.001823)
146 #
147 # failing examples: 5.should eq(3)
148 # * using the DSL
149 # 0.694148 0.002006 0.696154 ( 0.648551)
150 # 1.063773 0.004653 1.068426 ( 0.998837)
151 # 0.643594 0.001356 0.644950 ( 0.638358)
152 #
153 # * using a class
154 # 0.020139 0.000036 0.020175 ( 0.020161)
155 # 0.097540 0.000575 0.098115 ( 0.084680)
156 # 0.058366 0.000269 0.058635 ( 0.044372)
157 #
158 # 3 runs of 1000 times for each example running jruby/1.8.7
159 # passing examples: 5.should eq(5)
160 # * using the DSL
161 # 0.355000 0.000000 0.355000 ( 0.355000)
162 # 0.261000 0.000000 0.261000 ( 0.261000)
163 # 0.242000 0.000000 0.242000 ( 0.242000)
164 #
165 # * using a class
166 # 0.007000 0.000000 0.007000 ( 0.007000)
167 # 0.004000 0.000000 0.004000 ( 0.004000)
168 # 0.001000 0.000000 0.001000 ( 0.001000)
169 #
170 # failing examples: 5.should eq(3)
171 # * using the DSL
172 # 0.507000 0.000000 0.507000 ( 0.507000)
173 # 0.468000 0.000000 0.468000 ( 0.468000)
174 # 0.476000 0.000000 0.476000 ( 0.476000)
175 #
176 # * using a class
177 # 0.259000 0.000000 0.259000 ( 0.259000)
178 # 0.521000 0.000000 0.521000 ( 0.521000)
179 # 0.244000 0.000000 0.244000 ( 0.244000)
180 #
Something went wrong with that request. Please try again.