Sha256: 3c33f27cd84dad09a568e2ac5d762b0d0439da598a5bc9773532d6ad91bbd7ac

Contents?: true

Size: 1.44 KB

Versions: 31

Compression:

Stored size: 1.44 KB

Contents

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

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

31 entries across 31 versions & 4 rubygems

Version Path
draper_new-3.0.0 spec/performance/benchmark.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/draper-2.1.0/spec/performance/benchmark.rb
draper-2.1.0 spec/performance/benchmark.rb
draper-2.0.0 spec/performance/benchmark.rb
draper-1.4.0 spec/performance/benchmark.rb
draper-1.3.1 spec/performance/benchmark.rb
draper-1.3.0 spec/performance/benchmark.rb
draper-1.2.1 spec/performance/benchmark.rb
draper-1.2.0 spec/performance/benchmark.rb
jamesgolick-draper-1.1.1a spec/performance/benchmark.rb
draper-1.1.0 spec/performance/benchmark.rb
draper-1.0.0 spec/performance/benchmark.rb
draper-1.0.0.beta6 spec/performance/benchmark.rb
draper-1.0.0.beta5 spec/performance/benchmark.rb
draper-1.0.0.beta4 spec/performance/benchmark.rb
draper-1.0.0.beta3 spec/performance/benchmark.rb
draper-1.0.0.beta2 spec/performance/benchmark.rb
draper-1.0.0.beta1 spec/performance/benchmark.rb
draper-0.18.0 performance/bechmark.rb
draper-0.17.0 performance/bechmark.rb