Skip to content

Commit

Permalink
Add benchmark for allocating 40k objects with + without oink:
Browse files Browse the repository at this point in the history
                     user     system      total        real
40,000 empty iterations  0.000000   0.000000   0.000000 (  0.002370)
without instance type counter - instantiating 40,000 objects  0.910000   0.020000   0.930000 (  0.922722)
with instance type counter - instating 40,000 objects  2.620000   0.070000   2.690000 (  2.700390)
  • Loading branch information
smtlaissezfaire committed Mar 15, 2010
1 parent 86c59e0 commit 3952d7a
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions benchmark/instance_counter_performance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env ruby

require 'benchmark'
require 'active_record'
require 'sqlite3'
require File.dirname(__FILE__) + "/../lib/oink.rb"
require File.dirname(__FILE__) + "/../init"

ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
ActiveRecord::Migration.verbose = false

ActiveRecord::Schema.define do
create_table :users, :force => true do |t|
t.timestamps
end
end

class User < ActiveRecord::Base
end

Benchmark.bm(15) do |x|
x.report "40,000 empty iterations" do
40_000.times {}
end

x.report "without instance type counter - instantiating 40,000 objects" do
40_000.times do
User.new
end
end

x.report "with instance type counter - instating 40,000 objects" do
ActiveRecord::Base.send(:include, Oink::OinkInstanceTypeCounterInstanceMethods)

40_000.times do
User.new
end
end
end

0 comments on commit 3952d7a

Please sign in to comment.