Friday, May 13, 2011

Ruby Require Time

Last week in ruby-core mail list were circulating some horror charts of Ruby 'require' time for many .rb files. The most relevant is this one.

I can confirm the rather unpleasant statistics. I took the benchmark snippet from the link above and rewrote it into Rakefile. All it does is a creation of 18,000 empty files, and after that forces Ruby to 'require' them.

To run this benchmark on your machine, grab the source, place it into a file named Rakefile in a temporally directory, and type rake benchmark.

This is what I got in FreeBSD 8.2 under VMware Workstation 7.1.4:

$ rake clean benchmark # in RVM
(in /opt/samba/tmp/b)
rm -rf rec-files
mkdir -p rec-files
ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-freebsd8.2]
              user     system      total        real
500 requires  0.171875   0.171875   0.343750 (  0.372954)
1000 requires  0.460938   0.453125   0.914062 (  1.006835)
1500 requires  1.039062   0.539062   1.578125 (  1.703206)
2000 requires  1.382812   0.632812   2.015625 (  2.186040)
2500 requires  2.953125   0.804688   3.757812 (  4.125621)
3000 requires  5.265625   0.625000   5.890625 (  6.766446)
3500 requires  7.609375   1.062500   8.671875 ( 10.501926)
4000 requires 11.039062   0.671875  11.710938 ( 12.816059)

versus scary:

% rake clean benchmark
(in /opt/samba/tmp/b)
rm -rf rec-files
mkdir -p rec-files
ruby 1.9.2p0 (2010-08-18 revision 29036) [i386-freebsd8]
              user     system      total        real
500 requires  0.156250   0.195312   0.351562 (  0.391295)
1000 requires  0.953125   0.390625   1.343750 (  1.459771)
1500 requires  3.171875   0.773438   3.945312 (  4.448573)
2000 requires  7.132812   1.390625   8.523438 ( 10.009462)
2500 requires 13.554688   1.859375  15.414062 ( 17.039073)
3000 requires 23.382812   2.976562  26.359375 ( 31.123249)
3500 requires 36.859375   3.734375  40.593750 ( 44.460490)
4000 requires 54.843750   5.453125  60.296875 ( 66.162403)
https://lh6.googleusercontent.com/_W-OHaMHyRAE/Tc2UUY8j7nI/AAAAAAAAARQ/GY2PZJGGQz4/s800/ruby-require-stat.png

No comments:

Post a Comment