Created
May 7, 2011 10:11
-
-
Save erubboli/960383 to your computer and use it in GitHub Desktop.
method access vs variable access
This file contains hidden or 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
require 'benchmark' | |
def a_method | |
10 | |
end | |
a_var = 10 | |
Benchmark.bm do |x| | |
x.report("variable access") do | |
for i in 0..200000000 do | |
a_var | |
end | |
end | |
x.report("method access") do | |
for i in 0..200000000 do | |
a_method | |
end | |
end | |
end |
This file contains hidden or 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
variable access | |
user system total real | |
7.045000 0.000000 7.045000 ( 6.791000) | |
method access | |
user system total real | |
14.328000 0.000000 14.328000 ( 14.328000) |
This file contains hidden or 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
variable access | |
user system total real | |
6.630000 0.010000 6.640000 ( 6.630245) | |
method access | |
user system total real | |
15.790000 0.000000 15.790000 ( 15.792764) |
This file contains hidden or 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
variable access | |
user system total real | |
16.370000 0.000000 16.370000 ( 16.374627) | |
method access | |
user system total real | |
33.900000 0.010000 33.910000 ( 33.912025) |
This file contains hidden or 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
# using rvm 1.9.2-p180 | |
variable access | |
user system total real | |
13.800000 0.030000 13.830000 ( 13.896888) | |
method access | |
user system total real | |
22.180000 0.060000 22.240000 ( 22.345057) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment