Skip to content

Instantly share code, notes, and snippets.

@RoxasShadow
Created February 1, 2014 18:08
Show Gist options
  • Select an option

  • Save RoxasShadow/8756020 to your computer and use it in GitHub Desktop.

Select an option

Save RoxasShadow/8756020 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'observer'
require 'alakazam'
class Logger
def update(*things)
#
end
end
class ObservableImplementation
include Observable
def do
changed
notify_observers hurr: 'durr'
end
end
class AlakazamImplementation
include Alakazam
extend Alakazam
def do
fire!
fire hurr: 'durr'
end
end
iterations = 1000_000
Benchmark.bm(27) do |bm|
bm.report('observable') do
iterations.times {
implementation = ObservableImplementation.new
implementation.add_observer Logger.new
implementation.do
}
end
bm.report('alakazam') do
iterations.times {
implementation = AlakazamImplementation.new
implementation.add_observer Logger.new
implementation.do
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment