forked from rspec/rspec-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequire_relative_v_require.rb
75 lines (67 loc) · 2.43 KB
/
require_relative_v_require.rb
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'benchmark'
n = 20
Benchmark.benchmark do |bm|
3.times.each do
bm.report do
n.times do
pid = fork do
require 'rspec/core'
end
Process.wait(pid)
end
end
end
end
# ###################################
# Ruby 1.9.3 - 3 x 20
# require
# $ bundle exec ruby benchmarks/require_relative_v_require.rb
# 0.000000 0.020000 2.540000 ( 2.568784)
# 0.000000 0.010000 2.550000 ( 2.580621)
# 0.000000 0.020000 2.510000 ( 2.548631)
#
# require_relative
# $ bundle exec ruby benchmarks/require_relative_v_require.rb
# 0.000000 0.010000 2.220000 ( 2.288229)
# 0.000000 0.010000 2.250000 ( 2.289886)
# 0.000000 0.020000 2.260000 ( 2.296639)
#
# roughly 12% improvement
#
# ###################################
#
# Ruby 1.8.7 - 3 x 20
# before change (using require, but no conditional)
# $ bundle exec ruby benchmarks/require_relative_v_require.rb
# 0.000000 0.010000 1.210000 ( 1.242291)
# 0.000000 0.010000 1.230000 ( 1.259518)
# 0.000000 0.010000 1.230000 ( 1.250333)
#
# after change (still using require, but adding conditional)
# $ bundle exec ruby benchmarks/require_relative_v_require.rb
# 0.000000 0.010000 1.200000 ( 1.227249)
# 0.000000 0.010000 1.230000 ( 1.257012)
# 0.000000 0.010000 1.230000 ( 1.259278)
#
# virtually no penalty
#
# ###################################
__END__
Ruby 2.0:
➜ rspec-core git:(benchmark-require-relative) REQUIRE_RELATIVE=1 bundle exec ruby benchmarks/require_relative_v_require.rb
0.000000 0.030000 1.470000 ( 1.481949)
0.000000 0.020000 1.440000 ( 1.462620)
0.000000 0.020000 1.470000 ( 1.491825)
➜ rspec-core git:(benchmark-require-relative) bundle exec ruby benchmarks/require_relative_v_require.rb
0.000000 0.010000 1.510000 ( 1.549906)
0.000000 0.010000 1.530000 ( 1.546252)
0.000000 0.020000 1.510000 ( 1.531644)
Ruby 2.1:
➜ rspec-core git:(benchmark-require-relative) bundle exec ruby benchmarks/require_relative_v_require.rb
0.000000 0.020000 1.570000 ( 1.613217)
0.000000 0.020000 1.600000 ( 1.618540)
0.010000 0.020000 1.570000 ( 1.608205)
➜ rspec-core git:(benchmark-require-relative) REQUIRE_RELATIVE=1 bundle exec ruby benchmarks/require_relative_v_require.rb
0.000000 0.020000 1.480000 ( 1.515131)
0.000000 0.010000 1.480000 ( 1.527766)
0.000000 0.020000 1.490000 ( 1.515631)