Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 950f6db

Browse files
committed
Benchmark the perf difference with a load path of different sizes.
1 parent 78daad6 commit 950f6db

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
ruby -v
2+
3+
function run_benchmark_with_load_path_size {
4+
pushd tmp
5+
mkdir -p boot_time_benchmark
6+
7+
local load_path_size=$1
8+
for (( i=0; i < $load_path_size; i++ )); do
9+
mkdir -p "boot_time_benchmark/dir_$i"
10+
done
11+
12+
local load_path=`ruby -e 'puts Array.new(Integer(ARGV.first)) { |i| "boot_time_benchmark/dir_#{i}" }.join(":")' $load_path_size`
13+
14+
echo "3 runs with $load_path_size dirs on load path, booting 50 times, using $2"
15+
for i in {1..3}; do
16+
time (for i in {1..50}; do ruby -I$load_path:../lib:../../rspec-support/lib -e 'require "rspec/core"'; done)
17+
done
18+
popd
19+
}
20+
21+
run_benchmark_with_load_path_size 10 "require"
22+
run_benchmark_with_load_path_size 100 "require"
23+
run_benchmark_with_load_path_size 1000 "require"
24+
25+
export REQUIRE_RELATIVE=1
26+
27+
run_benchmark_with_load_path_size 10 "require_relative"
28+
run_benchmark_with_load_path_size 100 "require_relative"
29+
run_benchmark_with_load_path_size 1000 "require_relative"
30+
31+
: <<'result_comment'
32+
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
33+
~/code/rspec-core/tmp ~/code/rspec-core
34+
3 runs with 10 dirs on load path, booting 50 times, using require
35+
36+
real 0m3.815s
37+
user 0m3.205s
38+
sys 0m0.519s
39+
40+
real 0m3.850s
41+
user 0m3.234s
42+
sys 0m0.527s
43+
44+
real 0m3.840s
45+
user 0m3.225s
46+
sys 0m0.525s
47+
~/code/rspec-core
48+
~/code/rspec-core/tmp ~/code/rspec-core
49+
3 runs with 100 dirs on load path, booting 50 times, using require
50+
51+
real 0m5.086s
52+
user 0m3.887s
53+
sys 0m1.107s
54+
55+
real 0m5.063s
56+
user 0m3.870s
57+
sys 0m1.098s
58+
59+
real 0m5.061s
60+
user 0m3.871s
61+
sys 0m1.097s
62+
~/code/rspec-core
63+
~/code/rspec-core/tmp ~/code/rspec-core
64+
3 runs with 1000 dirs on load path, booting 50 times, using require
65+
66+
real 0m18.850s
67+
user 0m11.057s
68+
sys 0m7.679s
69+
70+
real 0m18.783s
71+
user 0m11.012s
72+
sys 0m7.657s
73+
74+
real 0m18.747s
75+
user 0m10.992s
76+
sys 0m7.639s
77+
~/code/rspec-core
78+
~/code/rspec-core/tmp ~/code/rspec-core
79+
3 runs with 10 dirs on load path, booting 50 times, using require_relative
80+
81+
real 0m3.794s
82+
user 0m3.200s
83+
sys 0m0.506s
84+
85+
real 0m3.769s
86+
user 0m3.180s
87+
sys 0m0.502s
88+
89+
real 0m3.787s
90+
user 0m3.192s
91+
sys 0m0.502s
92+
~/code/rspec-core
93+
~/code/rspec-core/tmp ~/code/rspec-core
94+
3 runs with 100 dirs on load path, booting 50 times, using require_relative
95+
96+
real 0m4.626s
97+
user 0m3.620s
98+
sys 0m0.910s
99+
100+
real 0m4.652s
101+
user 0m3.642s
102+
sys 0m0.915s
103+
104+
real 0m4.678s
105+
user 0m3.662s
106+
sys 0m0.924s
107+
~/code/rspec-core
108+
~/code/rspec-core/tmp ~/code/rspec-core
109+
3 runs with 1000 dirs on load path, booting 50 times, using require_relative
110+
111+
real 0m14.400s
112+
user 0m8.615s
113+
sys 0m5.675s
114+
115+
real 0m14.495s
116+
user 0m8.672s
117+
sys 0m5.711s
118+
119+
real 0m14.541s
120+
user 0m8.705s
121+
sys 0m5.727s
122+
~/code/rspec-core
123+
result_comment

0 commit comments

Comments
 (0)