Last active
December 14, 2015 06:19
-
-
Save marcandre/5041813 to your computer and use it in GitHub Desktop.
benchmarking the new `caller_locations` against `caller`
This file contains 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 'fruity' | |
def whoze_there_using_caller | |
caller[0][/`([^']*)'/, 1] | |
end | |
def whoze_there_using_locations | |
caller_locations(1,1)[0].label | |
end | |
def test(stack_level = 0) | |
return test(stack_level-1) unless stack_level <= 0 | |
compare do | |
using_caller { whoze_there_using_caller } | |
using_locations { whoze_there_using_locations } | |
end | |
end | |
test | |
puts "With a longer stacktrace:" | |
test(100) | |
# => | |
# using_locations is faster than using_caller by 46x ± 1.0 | |
# With a longer stacktrace: | |
# Running each test 1024 times. Test will take about 3 seconds. | |
# using_locations is faster than using_caller by 101x ± 10.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment