Created
August 17, 2013 09:42
-
-
Save ysmood/6256136 to your computer and use it in GitHub Desktop.
Performance test of the variable in different scopes.
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
| $g = 10 | |
| def fun_g a | |
| a += $g | |
| end | |
| def fun_l a | |
| l = 10 | |
| a += l | |
| end | |
| def fun_gl a | |
| $gl = 10 | |
| a += $gl | |
| end | |
| def test fun | |
| t = Time.now | |
| (10 ** 6).times { |n| | |
| method(fun).call(n) | |
| } | |
| puts(Time.now - t) | |
| end | |
| test :fun_g | |
| test :fun_l | |
| test :fun_gl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment