-
-
Notifications
You must be signed in to change notification settings - Fork 763
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using require_relative instead of require results in a roughly 12% improvement in the time it takes to load rspec-core's own lib files
- Loading branch information
1 parent
032f373
commit c59cdf8
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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 | ||
# | ||
# ################################### |