Skip to content

Instantly share code, notes, and snippets.

View gamache's full-sized avatar
🤙

pete gamache gamache

🤙
View GitHub Profile
@gamache
gamache / method-cache-test.rb
Last active December 25, 2015 10:38
Code to test relative performace penalty of invalidating the MRI Ruby method cache, versus performing method resolution manually via method_missing. (Edit 1: pinpoint the overhead of Class.new by comparing it to a trivial Object#extend; thanks @joshjordanwhat! Edit 2: added optional warm-up to make JRuby benchmarks make more sense.)
require 'benchmark'
module A; end
class DefinedMethodStyle
def bust_cache_class(*); Class.new; nil end
def bust_cache_extend(*); Object.new.extend(A); nil end
def dont_bust_cache(*); Object.new; nil end
end