This is a theoretical benchmark of require
time comparing ruby 1.9.4 r33453 original and patched on a 64-bit Linux with a sequential hard disk.
It is theoretical because it is based on requiring a few hundreds empty files from the same folder, which is likely rare.
However, the global result (patched significantly faster than original) should be reflected in a certain measure in real life.
It is showing especially good results, because a file is never required twice, and so the unpatched version always has to check every file loaded.
The patched version could actually be slower when:
- there are a lot of files loaded
- the user tries many times to require one of the first files loaded
But I could not confirm this in my benchmarks, and this case should never happen (because the first files loaded are loaded by ruby before running the code).
The benchmark was ran 20 times for each ruby. I also ran a manual benchmark on each ruby and the results are similar, it was just a bit faster on the original than expected.
Making good benchmarks is hard, so please teach me if I made a mistake. However, I'm confident about this one.
And, a big "thank you" to Yura Sokolov for this patch!
P.S.: The same benchmark ran on 1.8.7 can be seen at https://gist.github.com/1279106
I tried to test "worst case" yesterday. It seems that 10000 requires of 'enc/encdb' (second required file) after 2000 other required files with patched version is worse by only ~0.05 seconds (0.56s on patched version instead of 0.52s on unpatched). But overall saved time is about 1.5s (patched version takes 1.137s, unpatched 2.694s) - requiring of 2000 files compensates any slowdown of requiring 'enc/encdb' :)
(
tmp
directory were filled withrequire "fileutils"; 2000.times{|i| FileUtils.touch("tmp/#{i}.rb"); FileUtils.touch("tmp/r#{i}.rb") }