Skip to content

Instantly share code, notes, and snippets.

@Locke23rus
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Locke23rus/96276a524ada8b43d1c1 to your computer and use it in GitHub Desktop.
Save Locke23rus/96276a524ada8b43d1c1 to your computer and use it in GitHub Desktop.
Slow require for the first not exist file

MRI

$ ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]

$ ruby slow_require.rb
3.15ms - time
21.05ms - oj/error
85.68ms - not_exist_file1
6.99ms - not_exist_file2

$ ruby --disable-gems slow_require.rb
5.88ms - time
0.19ms - oj/error
0.17ms - not_exist_file1
0.15ms - not_exist_file2

JRuby

$ ruby -v
jruby 1.7.18 (1.9.3p551) 2014-12-22 625381c on OpenJDK 64-Bit Server VM 1.8.0_25-b18 +jit [linux-amd64]

$ ruby slow_require.rb
169.0ms - time
288.0ms - oj/error
11.0ms - not_exist_file1
13.0ms - not_exist_file2

$ ruby --disable-gems slow_require.rb
289.0ms - time
2.0ms - oj/error
2.0ms - not_exist_file1
1.0ms - not_exist_file2

Rubinius

$ ruby -v
rubinius 2.4.1 (2.1.0 b332f133 2014-12-04 3.5.0 JI) [x86_64-linux-gnu]

$ ruby slow_require.rb
37.87ms - time
522.34ms - oj/error
18.1ms - not_exist_file1
16.32ms - not_exist_file2

$ ruby --disable-gems slow_require.rb
75.39ms - time
1.14ms - oj/error
0.74ms - not_exist_file1
0.73ms - not_exist_file2
def stamp(name)
start_time = Time.now
begin
require name
rescue LoadError
end
ensure
time = (Time.now - start_time) * 1000
puts "#{time.round(2)}ms - #{name}"
end
stamp 'time'
stamp 'oj/error' # just a file from some gem w/o extra dependencies
stamp 'not_exist_file1'
stamp 'not_exist_file2'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment