Skip to content

Commit

Permalink
Add a benchmark about using JS Symbols vs Strings
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Oct 31, 2018
1 parent 371c195 commit 2a53e88
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions benchmark-ips/bm_js_symbols_vs_strings.rb
@@ -0,0 +1,28 @@
Benchmark.ips do |x|
%x{
var o = {}
o[Symbol.for('foo')] = 123
o.foo = 123
var foo = Symbol('foo')
o[foo] = 123
var a = 0, b = 0, c = 0
}

x.report('global symbol') do
`a += o[Symbol.for('foo')]`
end

x.report('symbol') do
`a += o[foo]`
end

x.report('ident') do
`b += o.foo`
end

x.report('string') do
`c += o['foo']`
end

x.compare!
end

0 comments on commit 2a53e88

Please sign in to comment.