Skip to content

Instantly share code, notes, and snippets.

@fphilipe
Created Nov 10, 2015
Embed
What would you like to do?
Calculating -------------------------------------
on_server_error :notify_honeybadger
90.832k i/100ms
on_server_error &Honeybadger.method(:notify)
96.540k i/100ms
on_server_error { |e| Honeybadger.notify(e) }
90.455k i/100ms
-------------------------------------------------
on_server_error :notify_honeybadger
2.007M (± 7.9%) i/s - 9.992M
on_server_error &Honeybadger.method(:notify)
2.385M (± 4.6%) i/s - 11.971M
on_server_error { |e| Honeybadger.notify(e) }
3.047M (± 5.1%) i/s - 15.196M
Comparison:
on_server_error { |e| Honeybadger.notify(e) }: 3046514.7 i/s
on_server_error &Honeybadger.method(:notify): 2384889.1 i/s - 1.28x slower
on_server_error :notify_honeybadger: 2007348.7 i/s - 1.52x slower
module Honeybadger
def self.notify(error)
end
end
# Stripped down implementation.
module ServerError
def self.included(klass)
klass.extend(ClassMethods)
end
def fail
self.class.server_error_callback['something went wrong']
end
module ClassMethods
attr_reader :server_error_callback
def on_server_error(method = nil, &callback_block)
@server_error_callback =
if callback_block
callback_block
else
->(error) { send(method, error) if self.respond_to? method }
end
end
end
end
class A
include ServerError
on_server_error :notify_honeybadger
def self.notify_honeybadger(error)
Honeybadger.notify(error)
end
end
class B
include ServerError
on_server_error &Honeybadger.method(:notify)
end
class C
include ServerError
on_server_error { |e| Honeybadger.notify(e) }
end
a = A.new
b = B.new
c = C.new
require 'benchmark/ips'
Benchmark.ips do |x|
x.report('on_server_error :notify_honeybadger') { a.fail }
x.report('on_server_error &Honeybadger.method(:notify)') { b.fail }
x.report('on_server_error { |e| Honeybadger.notify(e) }') { c.fail }
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment