Sha256: ba3c748d9ad343296b2860181e5ea681a10a1f373aa59990270dd35f935d8683

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

require 'rubygems'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Bundler.require :default

require "benchmark"
require "draper"
require "./performance/models"
require "./performance/decorators"

Benchmark.bm do |bm|
  puts "\n[ Exclusivelly using #method_missing for model delegation ]"
  [ 1_000, 10_000, 100_000 ].each do |i|
    puts "\n[ #{i} ]"
    bm.report("#new                 ") do
      i.times do |n|
        ProductDecorator.decorate(Product.new)
      end
    end

    bm.report("#hello_world         ") do
      i.times do |n|
        ProductDecorator.decorate(Product.new).hello_world
      end
    end

    bm.report("#sample_class_method ") do
      i.times do |n|
        ProductDecorator.decorate(Product.new).class.sample_class_method
      end
    end
  end

  puts "\n[ Defining methods on method_missing first hit ]"
  [ 1_000, 10_000, 100_000 ].each do |i|
    puts "\n[ #{i} ]"
    bm.report("#new                 ") do
      i.times do |n|
        FastProductDecorator.decorate(FastProduct.new)
      end
    end

    bm.report("#hello_world         ") do
      i.times do |n|
        FastProductDecorator.decorate(FastProduct.new).hello_world
      end
    end

    bm.report("#sample_class_method ") do
      i.times do |n|
        FastProductDecorator.decorate(FastProduct.new).class.sample_class_method
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
draper-4.0.2 spec/performance/benchmark.rb
draper-4.0.1 spec/performance/benchmark.rb
draper-4.0.0 spec/performance/benchmark.rb
draper-3.1.0 spec/performance/benchmark.rb
draper-3.0.1 spec/performance/benchmark.rb
draper-3.0.0 spec/performance/benchmark.rb
draper-3.0.0.pre1 spec/performance/benchmark.rb