Skip to content

Instantly share code, notes, and snippets.

@marcandre
Last active December 14, 2015 06:19
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 marcandre/5041813 to your computer and use it in GitHub Desktop.
Save marcandre/5041813 to your computer and use it in GitHub Desktop.
benchmarking the new `caller_locations` against `caller`
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