Skip to content

Commit 2a53e88

Browse files
committed
Add a benchmark about using JS Symbols vs Strings
1 parent 371c195 commit 2a53e88

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Benchmark.ips do |x|
2+
%x{
3+
var o = {}
4+
o[Symbol.for('foo')] = 123
5+
o.foo = 123
6+
var foo = Symbol('foo')
7+
o[foo] = 123
8+
var a = 0, b = 0, c = 0
9+
}
10+
11+
x.report('global symbol') do
12+
`a += o[Symbol.for('foo')]`
13+
end
14+
15+
x.report('symbol') do
16+
`a += o[foo]`
17+
end
18+
19+
x.report('ident') do
20+
`b += o.foo`
21+
end
22+
23+
x.report('string') do
24+
`c += o['foo']`
25+
end
26+
27+
x.compare!
28+
end

0 commit comments

Comments
 (0)