Sha256: 778a61e996f66007513f5a4ca34de1cbead543c0333b625ee566daa49d656e32

Contents?: true

Size: 1.7 KB

Versions: 158

Compression:

Stored size: 1.7 KB

Contents

require 'rubygems'
require 'active_resource'
require 'benchmark'

TIMES = (ENV['N'] || 10_000).to_i

# deep nested resource
attrs = {
  :id => 1,
  :name => 'Luis',
  :age => 21,
  :friends => [
    {
      :name => 'JK',
      :age => 24,
      :colors => ['red', 'green', 'blue'],
      :brothers => [
        {
          :name => 'Mateo',
          :age => 35,
          :children => [{ :name => 'Edith', :age => 5 }, { :name => 'Martha', :age => 4 }]
        },
        {
          :name => 'Felipe',
          :age => 33,
          :children => [{ :name => 'Bryan', :age => 1 }, { :name => 'Luke', :age => 0 }]
        }
      ]
    },
    {
      :name => 'Eduardo',
      :age => 20,
      :colors => [],
      :brothers => [
        {
          :name => 'Sebas',
          :age => 23,
          :children => [{ :name => 'Andres', :age => 0 }, { :name => 'Jorge', :age => 2 }]
        },
        {
          :name => 'Elsa',
          :age => 19,
          :children => [{ :name => 'Natacha', :age => 1 }]
        },
        {
          :name => 'Milena',
          :age => 16,
          :children => []
        }
      ]
    }
  ]
}

class Customer < ActiveResource::Base
  self.site = "http://37s.sunrise.i:3000"
end

module Nested
  class Customer < ActiveResource::Base
    self.site = "http://37s.sunrise.i:3000"
  end
end

Benchmark.bm(40) do |x|
  x.report('Model.new (instantiation)')              { TIMES.times { Customer.new } }
  x.report('Nested::Model.new (instantiation)')      { TIMES.times { Nested::Customer.new } }
  x.report('Model.new (setting attributes)')         { TIMES.times { Customer.new attrs } }
  x.report('Nested::Model.new (setting attributes)') { TIMES.times { Nested::Customer.new attrs } }
end

Version data entries

158 entries across 132 versions & 11 rubygems

Version Path
active_mailer-0.0.3 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activeresource-3.2.12/examples/performance.rb
activeresource-3.2.12 examples/performance.rb
activeresource-3.1.11 examples/performance.rb
challah-0.9.1.beta.3 vendor/bundle/gems/activeresource-3.2.11/examples/performance.rb
devise_sociable-0.1.0 vendor/bundle/gems/activeresource-3.2.11/examples/performance.rb
challah-0.9.1.beta vendor/bundle/gems/activeresource-3.2.11/examples/performance.rb
activeresource-3.2.11 examples/performance.rb
activeresource-3.1.10 examples/performance.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/activeresource-3.2.10/examples/performance.rb
challah-0.9.0 vendor/bundle/gems/activeresource-3.2.9/examples/performance.rb
activeresource-3.2.10 examples/performance.rb
activeresource-3.1.9 examples/performance.rb
challah-rolls-0.2.0 vendor/bundle/gems/activeresource-3.2.8/examples/performance.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/activeresource-3.2.7/examples/performance.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/activeresource-3.2.8/examples/performance.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/activeresource-3.2.9/examples/performance.rb
challah-rolls-0.2.0 vendor/bundle/gems/activeresource-3.2.7/examples/performance.rb
challah-rolls-0.2.0 vendor/bundle/gems/activeresource-3.2.9/examples/performance.rb
challah-0.8.3 vendor/bundle/gems/activeresource-3.2.8/examples/performance.rb
challah-0.8.3 vendor/bundle/gems/activeresource-3.2.9/examples/performance.rb