forked from abrandoned/ffi-radix_tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
81 lines (63 loc) · 2.11 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
require "bundler/gem_tasks"
require "rake/testtask"
import "ext/ffi/radixtree/Rakefile"
namespace :radixtree do
desc "build radixtree"
task :compile do
Rake::Task[:compile_radixtree].invoke
end
desc "run benchmarks for radixtree lib"
task :benchmark do
require "benchmark/ips"
require "./lib/ffi/radix_tree"
radix_tree = ::FFI::RadixTree::Tree.new
(1..1000).each do |number|
radix_tree.push(number.to_s, "DERP#{number}" * (number % 10))
radix_tree.push(number.to_s * 100, "DERP#{number}" * (number % 10))
radix_tree.push(number.to_s * 1000, "DERP#{number}" * (number % 10))
end
::Benchmark.ips do |x|
x.config(:warmup => 10)
x.report("get") do
radix_tree.get(rand(1000).to_s * [1, 100, 100].sample)
end
x.report("longest prefix") do
radix_tree.longest_prefix(rand(1000).to_s * [1, 100, 100].sample)
end
x.report("get then value") do
val = rand(1000).to_s * [1, 100, 100].sample
radix_tree.longest_prefix(val)
radix_tree.longest_prefix_value(val)
end
x.report("prefix and value (combined)") do
radix_tree.longest_prefix_and_value(rand(1000).to_s * [1, 100, 100].sample)
end
x.report("longest prefix (miss)") do
radix_tree.longest_prefix("DERP DERPIE")
end
x.report("prefix and value (combined/miss)") do
radix_tree.longest_prefix_and_value("DERP DERPIE")
end
x.report("greedy match") do
radix_tree.greedy_match(rand(1000).to_s * [1, 100, 100].sample)
end
x.report("greedy match (miss)") do
radix_tree.greedy_match("DERP DERPIE")
end
x.report("greedy substring match") do
radix_tree.greedy_substring_match(rand(1000).to_s * [1, 100, 100].sample)
end
x.report("greedy substring match (miss)") do
radix_tree.greedy_substring_match("DERP DERPIE")
end
end
end
end
Rake::TestTask.new(:spec) do |t|
t.libs << "spec"
t.libs << "lib"
t.pattern = "spec/**/*_spec.rb"
t.verbose = true
end
Rake::Task[:spec].prerequisites << "radixtree:compile"
task :default => :spec