-
-
Notifications
You must be signed in to change notification settings - Fork 938
Expand file tree
/
Copy pathbench_string_conversions.rb
More file actions
66 lines (55 loc) · 918 Bytes
/
bench_string_conversions.rb
File metadata and controls
66 lines (55 loc) · 918 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
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
# frozen-string-literal: true
require 'benchmark/ips'
def intern(a)
a.intern
end
def to_i(a)
a.to_i
end
def to_f(a)
a.to_f
end
SYM_FSTRING = "string"
SYM_NORMAL = +SYM_FSTRING
INT_FSTRING = "1000"
INT_NORMAL = +INT_FSTRING
FLO_FSTRING = "1000.0"
FLO_NORMAL = +FLO_FSTRING
Benchmark.ips do |bm|
bm.report("intern normal") do |i|
while i > 0
intern(SYM_NORMAL)
i-=1
end
end
bm.report("intern fstring") do |i|
while i > 0
intern(SYM_FSTRING)
i-=1
end
end
bm.report("to_i normal") do |i|
while i > 0
to_i(INT_NORMAL)
i-=1
end
end
bm.report("to_i fstring") do |i|
while i > 0
to_i(INT_FSTRING)
i-=1
end
end
bm.report("to_f normal") do |i|
while i > 0
to_f(FLO_NORMAL)
i-=1
end
end
bm.report("to_f fstring") do |i|
while i > 0
to_f(FLO_FSTRING)
i-=1
end
end
end