Sha256: 463750b0377e74af9f2887502f9f0ac5e56bcc885fd3e3980c6706d5f84217d4
Contents?: true
Size: 1.92 KB
Versions: 2
Compression:
Stored size: 1.92 KB
Contents
require 'benchmark_driver' Benchmark.driver do |x| x.prelude <<~RUBY require 'active_support/callbacks' require 'active_support/core_ext/object/blank' class Record include ActiveSupport::Callbacks define_callbacks :save def save run_callbacks :save do puts "- save" end end end class PersonRecord < Record set_callback :save, :before, :saving_message def saving_message puts "saving..." end set_callback :save, :after do |object| puts "saved" end end require 'tiny_hooks' class TinyRecord include TinyHooks def save puts '- save' end end class TinyPersonRecord < TinyRecord def saving_message puts 'saving...' end define_hook :before, :save do saving_message end define_hook :after, :save do puts 'saved' end end person = PersonRecord.new tiny_person = TinyPersonRecord.new RUBY x.report 'ActiveSupport', %( person.save ) x.report 'TinyHooks', %( tiny_person.save ) end Benchmark.driver do |x| x.prelude <<~RUBY require 'active_support/callbacks' require 'active_support/core_ext/object/blank' class ASNoCallbackSet include ActiveSupport::Callbacks define_callbacks :save def save run_callbacks :save do puts "- save" end end end require 'tiny_hooks' class TinyNoCallbackSet include TinyHooks def save puts '- save' end end class Plain def save puts '- save' end end as_no_callback_set = ASNoCallbackSet.new tiny_no_callback_set = TinyNoCallbackSet.new plain = Plain.new RUBY x.report 'ActiveSupport no callback set', %( as_no_callback_set.save ) x.report 'TinyHooks no callback set', %( tiny_no_callback_set.save ) x.report 'Plain', %( plain.save ) end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tiny_hooks-2.0.0 | benchmark/compare_to_as_callbacks.rb |
tiny_hooks-1.0.0 | benchmark/compare_to_as_callbacks.rb |