-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
32 lines (27 loc) · 726 Bytes
/
Rakefile
File metadata and controls
32 lines (27 loc) · 726 Bytes
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
require 'rspec/core/rake_task'
task :default => :benchmark
task :benchmark do
require 'benchmark'
$:.unshift File.expand_path('../lib', __FILE__)
require 'postal_code'
codes = File.readlines(File.expand_path('../data/random_codes', __FILE__)).map {|c| c.strip!}
n = 100
Benchmark.benchmark(Benchmark::CAPTION, 25) do |x|
x.report("same postal code") do
n.times do
PostalCode.find("906-0601")
end
end
x.report("different postals code") do
n.times do
random_code = codes[rand(codes.size)]
PostalCode.find(random_code)
end
end
x.report("invalid postal code") do
n.times do
PostalCode.find("999-9999")
end
end
end
end