-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparams.rb
43 lines (40 loc) · 875 Bytes
/
params.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
require 'benchmark'
def hash(options)
result = "#{options.delete(:name)}"
for key, value in options
result << " #{key} => #{value} "
end
result
end
def optional(name, a = nil, b = nil, c = nil)
result = "#{name}"
options = { :a => a, :b => b, :c => c }
for key, value in options
result << " #{key} => #{value} "
end
result
end
COUNT = 100_000
data = "Content-Length: 100"
Benchmark.bmbm(25) do |bench|
bench.report('hash') do
COUNT.times do
hash({:name => 'name'})
end
end
bench.report('optional') do
COUNT.times do
optional('name')
end
end
bench.report('hash_with_option') do
COUNT.times do
hash({:name => 'name', :a => 'a', :b => 'b', :c => 'c'})
end
end
bench.report('optional_with_option') do
COUNT.times do
optional('name', :a => 'a', :b => 'b', :c => 'c')
end
end
end