Skip to content

Instantly share code, notes, and snippets.

@lifo

lifo/2_3_output Secret

Created Jan 21, 2010
Embed
What would you like to do?
Thread ID: 2148366640
Total: 0.100092
%self total self wait child calls name
57.47 0.08 0.06 0.00 0.02 10000 User(id: integer, name: string, email: string, created_at: datetime, updated_at: datetime)#id (/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/attribute_methods.rb:211}
21.04 0.10 0.02 0.00 0.08 1 Integer#times (ruby_runtime:0}
10.92 0.01 0.01 0.00 0.00 10000 String#to_i (ruby_runtime:0}
10.53 0.01 0.01 0.00 0.00 10000 Hash#[] (ruby_runtime:0}
0.04 0.10 0.00 0.00 0.10 1 Global#[No method] (performance.rb:82}
Thread ID: 2148366640
Total: 0.658645
%self total self wait child calls name
18.66 0.17 0.12 0.00 0.05 10000 ActiveRecord::ConnectionAdapters::Column#type_cast (/Users/lifo/commit-rails/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb:67}
14.94 0.35 0.10 0.00 0.25 10000 ActiveRecord::Attributes::Typecasting#typecast_read (/Users/lifo/commit-rails/rails/activerecord/lib/active_record/attributes/typecasting.rb:103}
9.03 0.12 0.06 0.00 0.06 10000 ActiveRecord::Attributes::Aliasing#unalias (/Users/lifo/commit-rails/rails/activerecord/lib/active_record/attributes/aliasing.rb:34}
7.55 0.41 0.05 0.00 0.36 10000 ActiveRecord::Attributes::Typecasting#[] (/Users/lifo/commit-rails/rails/activerecord/lib/active_record/attributes/typecasting.rb:26}
6.30 0.58 0.04 0.00 0.53 10000 ActiveRecord::Attributes::Aliasing#[] (/Users/lifo/commit-rails/rails/activerecord/lib/active_record/attributes/aliasing.rb:22}
6.30 0.05 0.04 0.00 0.01 30000 Hash#[] (ruby_runtime:0}
6.22 0.64 0.04 0.00 0.59 10000 #<Module:0x101632868>#id (/Users/lifo/commit-rails/rails/activerecord/lib/active_record/attribute_methods/read.rb:59}
4.67 0.20 0.03 0.00 0.17 10000 ActiveRecord::Type::Casting#cast (/Users/lifo/commit-rails/rails/activerecord/lib/active_record/types/object.rb:5}
4.39 0.03 0.03 0.00 0.00 30000 Symbol#=== (ruby_runtime:0}
3.50 0.66 0.02 0.00 0.64 1 Integer#times (ruby_runtime:0}
3.18 0.02 0.02 0.00 0.00 10000 ActiveRecord::Attributes::Aliasing#aliases (/Users/lifo/commit-rails/rails/activerecord/lib/active_record/attributes/aliasing.rb:30}
3.08 0.02 0.02 0.00 0.00 10000 ActiveRecord::Attributes::Store#types (/Users/lifo/commit-rails/rails/activerecord/lib/active_record/attributes/store.rb:9}
2.91 0.02 0.02 0.00 0.00 10000 ActiveRecord::Attributes#_attributes (/Users/lifo/commit-rails/rails/activerecord/lib/active_record/attributes.rb:24}
2.80 0.02 0.02 0.00 0.00 10000 ActiveRecord::Type::Casting#appendable? (/Users/lifo/commit-rails/rails/activerecord/lib/active_record/types/object.rb:18}
1.84 0.01 0.01 0.00 0.00 10000 String#to_i (ruby_runtime:0}
1.58 0.01 0.01 0.00 0.00 10000 Hash#default (ruby_runtime:0}
1.53 0.01 0.01 0.00 0.00 10000 String#to_s (ruby_runtime:0}
1.52 0.01 0.01 0.00 0.00 10000 Kernel#nil? (ruby_runtime:0}
0.01 0.66 0.00 0.00 0.66 1 Global#[No method] (performance.rb:82}
TIMES = 10000
if ENV['RAILS'] == '2.3'
require 'rubygems'
require 'active_record'
else
require File.join(File.dirname(__FILE__), "rails/vendor/gems/environment")
require 'active_record'
end
require 'benchmark'
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => "ar_perf.db"
)
def migrate!
ActiveRecord::Base.connection.create_table :users, :force => true do |t|
t.string :name, :email
t.timestamps
end
ActiveRecord::Base.connection.create_table :exhibits, :force => true do |t|
t.belongs_to :user
t.string :name
t.text :notes
t.timestamps
end
end
migrate!
class User < ActiveRecord::Base
has_many :exhibits
end
class Exhibit < ActiveRecord::Base
belongs_to :user
def look; attributes end
def feel; look; user.name end
def self.look(exhibits) exhibits.each { |e| e.look } end
def self.feel(exhibits) exhibits.each { |e| e.feel } end
end
migrate!
User.create! :name => 'lifo'
user = User.first
require 'ruby-prof'
result = RubyProf.profile do
10000.times { user.id }
end
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment