Created
May 2, 2012 20:31
-
-
Save cbandy/2580197 to your computer and use it in GitHub Desktop.
DCI Benchmarks - http://mikepackdev.com/blog_posts/22-benchmarking-dci-in-ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| require 'delegate' | |
| class DecorateUser | |
| end | |
| class RunnerDecorator < DelegateClass(DecorateUser) | |
| def initialize(user) | |
| super user | |
| end | |
| def run | |
| Math.tan(Math::PI / 4) | |
| end | |
| end | |
| Benchmark.bm do |bench| | |
| 3.times do | |
| bench.report('decorate') do | |
| 1000000.times do | |
| user = RunnerDecorator.new(DecorateUser.new) | |
| user.run | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| class ExtendUser | |
| end | |
| module Runner | |
| def run | |
| Math.tan(Math::PI / 4) | |
| end | |
| end | |
| Benchmark.bm do |bench| | |
| 3.times do | |
| bench.report('extend') do | |
| 1000000.times do | |
| user = ExtendUser.new | |
| user.extend Runner | |
| user.run | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| module Runner | |
| def run | |
| Math.tan(Math::PI / 4) | |
| end | |
| end | |
| class IncludeUser | |
| include Runner | |
| end | |
| Benchmark.bm do |bench| | |
| 3.times do | |
| bench.report('include') do | |
| 1000000.times do | |
| user = IncludeUser.new | |
| user.run | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment