Skip to content

Instantly share code, notes, and snippets.

@ysmood
Created August 17, 2013 09:42
Show Gist options
  • Select an option

  • Save ysmood/6256136 to your computer and use it in GitHub Desktop.

Select an option

Save ysmood/6256136 to your computer and use it in GitHub Desktop.
Performance test of the variable in different scopes.
$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