public
Rubygem
Description: DataMapper - Core
Homepage: http://datamapper.org
Clone URL: git://github.com/sam/dm-core.git
commit  fc0435161512b11ed5faf6e12364a9f4976bed3e
tree    41747cfc9807be2f509599b540c5746ea0e8d572
parent  2f42d99c96158618143ce7565c11d97c249ba166
dm-core / script / profile.rb
100755 68 lines (54 sloc) 1.573 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env ruby
 
require File.join(File.dirname(__FILE__), '..', 'lib', 'data_mapper')
 
require 'ruby-prof'
 
OUTPUT = DataMapper.root / 'profile_results.txt'
 
SOCKET_FILE = Pathname.glob(%w[
/opt/local/var/run/mysql5/mysqld.sock
tmp/mysqld.sock
tmp/mysql.sock
/var/mysql/mysql.sock
]).find(&:socket?)
 
DataMapper::Logger.new(DataMapper.root / 'log' / 'dm.log', :debug)
DataMapper.setup(:default, "mysql://root@localhost/data_mapper_1?socket=#{SOCKET_FILE}")
 
class Exhibit
  include DataMapper::Resource
 
  property :id, Integer, :serial => true
  property :name, String
  property :zoo_id, Integer
  property :notes, String, :lazy => true
  property :created_on, Date
  property :updated_at, DateTime
 
end
 
touch_attributes = lambda do |exhibits|
  [*exhibits].each do |exhibit|
    exhibit.id
    exhibit.name
    exhibit.created_on
    exhibit.updated_at
  end
end
 
# RubyProf, making profiling Ruby pretty since 1899!
def profile(&b)
  result = RubyProf.profile &b
  printer = RubyProf::FlatPrinter.new(result)
  printer.print(OUTPUT.open('w+'))
end
 
profile do
  10_000.times { touch_attributes[Exhibit.get(1)] }
 
# repository(:default) do
# 10_000.times { touch_attributes[Exhibit.get(1)] }
# end
#
# 1000.times { touch_attributes[Exhibit.all(:limit => 100)] }
#
# repository(:default) do
# 1000.times { touch_attributes[Exhibit.all(:limit => 100)] }
# end
#
# 10.times { touch_attributes[Exhibit.all(:limit => 10_000)] }
#
# repository(:default) do
# 10.times { touch_attributes[Exhibit.all(:limit => 10_000)] }
# end
end
 
puts "Done!"