-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
144 lines (130 loc) · 3.55 KB
/
Rakefile
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
require(File.join(File.dirname(__FILE__), 'lib', 'initialize'))
namespace :db do
desc "Prepare test data"
task :prepare do
SETTINGS["number_of_accounts"].times do |account_id|
account = Account.fake(:_id => account_id)
p account_id
SETTINGS["products_per_account"].times do |product_id|
product = Product.fake(:account_id => account_id)
end
end
end
desc "Clear database"
task :clear do
connection = MongoRecord::Base.connection
connection.collection('products').remove()
connection.collection('accounts').remove()
end
desc "Clear & prepare database"
task :clear_and_prepare => ["clear", "prepare"]
end
namespace :benchmark do
desc "Wyszkiwanie"
task :products_find do
number_of_products = Product.count - 1
RBench.run(1) do
format :width => 80
column :times
column :one, :title => "[s]"
[1, 10, 100, 1_000].each do |times|
report "Wyszukiwanie produktow", times do
one do
begin
Product.find(rand(number_of_products)+1)
rescue
end
end
end
end
end
end
desc "Lista produktow konta"
task :account_products do
RBench.run(1) do
format :width => 80
column :times
column :one, :title => "[s]"
[1, 10, 100, 1_000].each do |times|
report "Lista produktow konta", times do
one { Product.find_by_account_id(rand(SETTINGS["number_of_accounts"]))}
end
end
end
end
desc "Lista produktow konta z rodzicami"
task :account_products_with_parents do
RBench.run(1) do
format :width => 80
column :times
column :one, :title => "[s]"
[1, 10, 100, 1_000].each do |times|
report "Lista produktow konta z rodzicami", times do
one { Product.find_by_account_id_with_parents(rand(SETTINGS["number_of_accounts"]))}
end
end
end
end
desc "Update ceny"
task :products_update do
number_of_products = Product.count - 1
RBench.run(1) do
format :width => 80
column :times
column :one, :title => "[s]"
[1, 10, 100, 1_000].each do |times|
report "Update produktow", times do
one do
begin
product = Product.find(rand(number_of_products)+1)
product.price = rand(10000)/100.0
product.save
rescue
end
end
end
end
end
end
desc "Usuwanie"
task :products_delete do
number_of_products = Product.count - 1
RBench.run(1) do
format :width => 80
column :times
column :one, :title => "[s]"
[1, 10, 100, 1_000].each do |times|
report "Usuwanie produktow", times do
one do
begin
Product.find(rand(number_of_products)+1).destroy
rescue
end
end
end
end
end
end
desc "Usuniecie konta"
task :accounts_delete do
number_of_accounts = Account.count - 1
RBench.run(1) do
format :width => 80
column :times
column :one, :title => "[s]"
[1, 10, 100, 1_000].each do |times|
report "Usuwanie kont", times do
one do
begin
Account.find(rand(number_of_accounts)+1).destroy
rescue
end
end
end
end
end
end
desc "Wszystkie benchamrki"
task :all => [:products_find, :account_products, :account_products_with_parents, :products_update, :products_delete, :accounts_delete]
end
task :default => ["benchmark:all"]