-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
64 lines (55 loc) · 1.24 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
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
# Benchmark
#-----------------------------------------------
desc "Compare with pure ruby and rubype"
task :benchmark do
require "benchmark/ips"
require "data-criteria"
require "data/criteria/version"
puts "ruby version: #{RUBY_VERSION}"
puts "data-criteria version: #{Data::Criteria::VERSION}"
users = [
{
id: 1,
name: "Takeshi",
city: 'Kagawa',
age: 33,
money: 100_000,
},
{
id: 2,
name: "Ryota",
city: 'Hiroshima',
age: 18,
money: 500,
},
{
id: 3,
name: "Masanori",
city: 'Hokkaido',
age: 14,
money: 30,
},
]
criteria = Data::Criteria.new(
name: /ta/i,
city: %w(Kagawa Hiroshima),
age: 0..20,
money: '>= 300',
)
filter = proc {|user|
user[:name] =~ /ta/i &&
%w(Kagawa Hiroshima).include?(user[:city]) &&
(0..20).include?(user[:age]) &&
user[:money] >= 300
}
Benchmark.ips do |x|
x.report('data-criteria') { users.select{|user| criteria.match_all?(user) } }
x.report('normal block') { users.select(&filter) }
x.compare!
end
end
task bm: :benchmark