forked from huacnlee/redis-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
180 lines (158 loc) · 5.46 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
require 'rake'
require "rspec"
require File.expand_path('../spec/spec_helper', __FILE__)
namespace :benchmark do
task :random_words do
random = RandomWord.new
Benchmark.bm do|bm|
bm.report("Generate 1 random words") do
1.times do |i|
name = random.next
end
end
bm.report("Generate 100 random words") do
100.times do |i|
name = random.next
end
end
bm.report("Generate 10,000 random words") do
10_000.times do |i|
name = random.next
end
end
bm.report("Generate 100,000 random words") do
100_000.times do |i|
name = random.next
end
end
bm.report("Generate 1,000,000 random words") do
1_000_000.times do |i|
name = random.next
end
end
end
end
task :index do
random = RandomWord.new
Redis::Search::Index.new(:type => "CategoryTest",
:title => random.next,
:id => 0,
:prefix_index_enable => true,
:score => 1).save
Benchmark.bm do|bm|
bm.report("Index 1,000 items") do
1_000.times do |i|
Redis::Search::Index.new(:type => "CategoryTest",
:title => random.next,
:id => i,
:prefix_index_enable => true,
:score => 1).save
end
end
end
end
task :complete do
keys_count = $redis.dbsize
puts "Complete Benchmark from [CategoryTest], current have (#{keys_count} keys) in Redis"
["c","ca","can","jack"].each do |q|
puts "Search by [#{q}]"
puts " #{'-'*90}"
puts " #{Redis::Search.complete("CategoryTest",q, :limit => 10).collect { |c| [c['id'],c['title']].join(':') }}"
puts " #{'-'*90}"
puts "There have [#{Redis::Search.complete("CategoryTest",q, :limit => 1000000).count}] items like '#{q}'"
Benchmark.bm do|bm|
bm.report(" 1 times") do
1.times do |i|
Redis::Search.complete("CategoryTest",q, :limit => 10)
end
end
bm.report(" 10 times") do
10.times do |i|
Redis::Search.complete("CategoryTest",q, :limit => 10)
end
end
bm.report(" 100 times") do
100.times do |i|
Redis::Search.complete("CategoryTest",q, :limit => 10)
end
end
end
puts ""
end
end
task :test1 do
Benchmark.bm do|bm|
puts " c result:\n#{Redis::Search.complete("CategoryTest","c", :limit => 10).collect { |c| c['title'] }}"
bm.report(" 'c' word 10 times") do
10.times do |i|
Redis::Search.complete("CategoryTest","c", :limit => 10)
end
end
puts " a result:\n#{Redis::Search.complete("CategoryTest","a", :limit => 10).collect { |c| c['title'] }}"
bm.report(" 'a' word 10 times") do
10.times do |i|
Redis::Search.complete("CategoryTest","a", :limit => 10)
end
end
puts " b result:\n#{Redis::Search.complete("CategoryTest","b", :limit => 10).collect { |c| c['title'] }}"
bm.report(" 'b' word 10 times") do
10.times do |i|
Redis::Search.complete("CategoryTest","b", :limit => 10)
end
end
puts " f result:\n#{Redis::Search.complete("CategoryTest","f", :limit => 10).collect { |c| c['title'] }}"
bm.report(" 'f' word 10 times") do
10.times do |i|
Redis::Search.complete("CategoryTest","f", :limit => 10)
end
end
puts " t result:\n#{Redis::Search.complete("CategoryTest","t", :limit => 10).collect { |c| c['title'] }}"
bm.report(" 't' word 10 times") do
10.times do |i|
Redis::Search.complete("CategoryTest","t", :limit => 10)
end
end
puts " d result:\n#{Redis::Search.complete("CategoryTest","d", :limit => 10).collect { |c| c['title'] }}"
bm.report(" 'd' word 10 times") do
10.times do |i|
Redis::Search.complete("CategoryTest","d", :limit => 10)
end
end
puts " m result:\n#{Redis::Search.complete("CategoryTest","m", :limit => 10).collect { |c| c['title'] }}"
bm.report(" 'm' word 10 times") do
10.times do |i|
Redis::Search.complete("CategoryTest","m", :limit => 10)
end
end
end
end
task :query do
keys_count = $redis.dbsize
puts "Query Benchmark from [CategoryTest], current have (#{keys_count} keys) in Redis"
["Cabalic","Latcher","Pectolite","Jackal"].each do |q|
puts "Search by [#{q}]"
puts " #{'-'*90}"
puts " #{Redis::Search.query("CategoryTest",q, :limit => 10).collect { |c| [c['id'],c['title']].join(':') }}"
puts " #{'-'*90}"
puts "There have [#{Redis::Search.query("CategoryTest",q, :limit => 1000000).count}] items like '#{q}'"
Benchmark.bm do|bm|
bm.report(" 1 times") do
1.times do |i|
Redis::Search.query("CategoryTest",q, :limit => 10)
end
end
bm.report(" 10 times") do
10.times do |i|
Redis::Search.query("CategoryTest",q, :limit => 10)
end
end
bm.report(" 100 times") do
100.times do |i|
Redis::Search.query("CategoryTest",q, :limit => 10)
end
end
end
puts ""
end
end
end