Create a gist now

Instantly share code, notes, and snippets.

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