-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
86 lines (73 loc) · 2.28 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
require 'rubygems'
require 'rake'
require 'echoe'
Echoe.new('easyredis','0.0.5') do |p|
p.description = "framework designed to make using redis as a database simpler"
p.url = "http://alecbenzer.github.com/easyredis/"
p.author = "Alec Benzer"
p.email = "alecbezer @nospam@ gmail.com"
p.ignore_pattern = ["*.rdb"]
p.development_dependencies = ["redis >=2.1.1"]
end
require 'benchmark'
require './tests/man'
def rand_name(length=2)
chars = []
length.times { chars << (rand(26) + 65).chr }
chars.join
end
namespace :bm do
task :clear do
puts "destroying #{Man.count} previous entries"
time = Benchmark.measure { Man.destroy_all }
puts time.format
end
task :add do
count = ENV["count"] ? ENV["count"].to_i : 25000
puts "adding #{count} new entries"
time = Benchmark::Tms.new
length = Math.log(3*count,26).round
count.times do
name = rand_name(length)
age = rand(100)
time += Benchmark.measure { m = Man.new ; m.name = name ; m.age = age }
end
puts time.format
end
task :populate => [:clear, :add]
task :search do
puts "searching #{Man.count} entries by a particular name"
name = Man.rand.name
count = -1
time = Benchmark.measure { count = Man.search_by(:name,name).count }
puts "retrived #{count} records in:"
puts (time*1000).format
end
task :singlesearch do
puts "seaching #{Man.count} entries by a particular age"
puts "NOTE: this metric is only relevant if Model#search is not detecting single-field searches and using Model#search_by"
age = rand(100)
t1 = Benchmark.measure { Man.search(:age => age) }
t2 = Benchmark.measure { Man.search_by(:age,age) }
puts "Model#search:"
puts (t1*1000).format
puts "Model#search_by:"
puts (t2*1000).format
puts "search is #{((t1.real/t2.real) - 1)*100}% slower"
end
task :multisearch do
man = Man.rand
name = man.name
age = man.age
count = 0
time = Benchmark.measure { count = Man.search(:name => name, :age => age).size }
puts "retrived #{count} out of #{Man.count} entries in:"
puts (time*1000).format
end
task :find do
puts "finding one of #{Man.count} entries by name"
name = Man.rand.name
time = Benchmark.measure { Man.find_by(:name,name) }
puts (time*1000).format
end
end