Skip to content

Instantly share code, notes, and snippets.

@jits
Forked from wuputah/lambda-vs-array.rb
Last active January 3, 2016 13:59
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 jits/8473194 to your computer and use it in GitHub Desktop.
Save jits/8473194 to your computer and use it in GitHub Desktop.
require 'benchmark'
def get_lambda
lambda { }
end
def my_method; end
Benchmark.bmbm do |x|
x.report { 1_000_000.times { method(:my_method) } }
x.report { 1_000_000.times { lambda { } } }
x.report { 1_000_000.times { get_lambda } }
x.report { 1_000_000.times { Array.new } }
end
__END__
ruby-1.9.3-p327
Rehearsal ------------------------------------
0.870000 0.020000 0.890000 ( 0.893942)
0.860000 0.040000 0.900000 ( 0.903918)
0.850000 0.040000 0.890000 ( 0.889628)
0.240000 0.000000 0.240000 ( 0.234580)
--------------------------- total: 2.920000sec
user system total real
0.910000 0.010000 0.920000 ( 0.922781)
0.810000 0.040000 0.850000 ( 0.842371)
0.900000 0.040000 0.940000 ( 0.937668)
0.250000 0.000000 0.250000 ( 0.251040)
ruby-2.0.0-p353
Rehearsal ------------------------------------
0.960000 0.020000 0.980000 ( 0.986903)
0.900000 0.030000 0.930000 ( 0.934319)
0.910000 0.050000 0.960000 ( 0.963130)
0.240000 0.000000 0.240000 ( 0.249599)
--------------------------- total: 3.110000sec
user system total real
0.930000 0.020000 0.950000 ( 0.953224)
0.880000 0.030000 0.910000 ( 0.912183)
0.930000 0.030000 0.960000 ( 0.968376)
0.220000 0.000000 0.220000 ( 0.225340)
ruby-2.1.0
Rehearsal ------------------------------------
0.930000 0.010000 0.940000 ( 0.942092)
1.110000 0.020000 1.130000 ( 1.131873)
1.020000 0.000000 1.020000 ( 1.040798)
0.240000 0.000000 0.240000 ( 0.233958)
--------------------------- total: 3.330000sec
user system total real
0.900000 0.010000 0.910000 ( 0.914917)
1.000000 0.010000 1.010000 ( 1.010687)
0.990000 0.010000 1.000000 ( 0.998085)
0.220000 0.000000 0.220000 ( 0.219945)
jruby-1.7.10
Rehearsal ------------------------------------
1.170000 0.040000 1.210000 ( 0.447000)
0.540000 0.020000 0.560000 ( 0.294000)
0.460000 0.030000 0.490000 ( 0.274000)
0.250000 0.010000 0.260000 ( 0.147000)
--------------------------- total: 2.520000sec
user system total real
0.090000 0.000000 0.090000 ( 0.091000)
0.160000 0.000000 0.160000 ( 0.129000)
0.140000 0.010000 0.150000 ( 0.134000)
0.110000 0.000000 0.110000 ( 0.107000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment