-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.rb
58 lines (49 loc) · 1.6 KB
/
benchmark.rb
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
$LOAD_PATH.unshift('./lib')
require 'rubygems'
require 'fuzzy_complete'
# c = FuzzyComplete::RedisFind.new(File.readlines('names.txt').map(&:chomp), 'foobar', Redis.new, FuzzyComplete::Codec::Yajl.new)
# c.logger.level = Logger::WARN
# c.find('user', ARGV[0]).each{|r| puts [r[:highlighted_name], r[:highlighted_permalink], r[:score]].inspect }
require 'benchmark'
people = File.readlines('names.txt').map(&:chomp).map{|line| line.split('|')}
c_yajl = FuzzyComplete::RedisFind.new(File.readlines('names.txt').map(&:chomp), 'foobar', Redis.new, FuzzyComplete::Codec::Yajl.new)
c_msgpack = FuzzyComplete::RedisFind.new(File.readlines('names.txt').map(&:chomp), 'foobar', Redis.new, FuzzyComplete::Codec::Msgpack.new)
c_yajl.logger.level = Logger::WARN
c_msgpack.logger.level = Logger::WARN
puts "Generating query terms"
query_terms = (0..10_000).to_a.map do |i|
name, permalink = people[rand(people.size)]
terms = [name, permalink].compact
term = terms[rand(terms.size)]
p0 = rand(term.size)
len = rand(term.size - p0)
term[p0, len]
end
puts "Yajl"
Benchmark.bm do |x|
x.report('prime ') do
system 'ruby clear.rb >/dev/null'
query_terms.each do |term|
c_yajl.find('user', term)
end
end
x.report('cached ') do
query_terms.each do |term|
c_yajl.find('user', term)
end
end
end
puts "Msgpack"
Benchmark.bm do |x|
x.report('prime ') do
system 'ruby clear.rb >/dev/null'
query_terms.each do |term|
c_msgpack.find('user', term)
end
end
x.report('cached ') do
query_terms.each do |term|
c_msgpack.find('user', term)
end
end
end