Skip to content

Instantly share code, notes, and snippets.

@wesleyskap
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save wesleyskap/ed92b0b7645b289e8dfd to your computer and use it in GitHub Desktop.

Select an option

Save wesleyskap/ed92b0b7645b289e8dfd to your computer and use it in GitHub Desktop.
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails',
github: 'rails/rails'
# path: '../../rails'
gem 'arel', github: 'rails/arel'
gem 'benchmark-ips'
end
class Record
include ActiveSupport::Callbacks
define_callbacks :halting_and_conditional
set_callback :halting_and_conditional, :around, ->(_, block) { block.call }, if: 'true'
def halting_and_conditional
run_callbacks :halting_and_conditional do
end
end
define_callbacks :halting
set_callback :halting, :around, ->(_, block) { block.call }
def halting
run_callbacks :halting do
end
end
end
Benchmark.ips do |x|
x.report('halting conditional') do
Record.new.halting_and_conditional
end
x.report('halting') do
Record.new.halting
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment