-
Notifications
You must be signed in to change notification settings - Fork 14
/
benchmark.rb
73 lines (66 loc) · 1.63 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'benchmark'
require_relative 'lib/message_format'
iterations = 100_000
Benchmark.bm do |bm|
bm.report('parse simple message') do
parser = MessageFormat::Parser.new()
iterations.times do
parser.parse("I'm a super simple message")
end
end
bm.report('format simple message') do
message = MessageFormat.new("I'm a super simple message")
iterations.times do
message.format()
end
end
bm.report('parse one arg message') do
parser = MessageFormat::Parser.new()
iterations.times do
parser.parse("I'm a { arg } message")
end
end
bm.report('format one arg message') do
message = MessageFormat.new("I'm a { arg } message")
iterations.times do
message.format({ :arg => 'awesome' })
end
end
bm.report('parse complex message') do
parser = MessageFormat::Parser.new()
iterations.times do
parser.parse('On {day, date, short} {
count, plural, offset:1
=0 {nobody carpooled.}
=1 {{driverName} drove {
driverGender, select,
male {himself}
female {herself}
other {themself}
}.}
other {{driverName} drove # people.}
}')
end
end
bm.report('format complex message') do
message = MessageFormat.new('On {day, date, short} {
count, plural, offset:1
=0 {nobody carpooled.}
=1 {{driverName} drove {
driverGender, select,
male {himself}
female {herself}
other {themself}
}.}
other {{driverName} drove # people.}
}')
iterations.times do
message.format({
:day => DateTime.now,
:count => 5,
:driverName => 'Jeremy',
:driverGender => 'male'
})
end
end
end