symbol-vs-weakmap (v6)

Revision 6 of this benchmark created by manvalls on


Description

there are two ways to define private variables in ES6. Let's see which one is faster

Preparation HTML

<script>

var symbol = Symbol();
var weakMap = new WeakMap();
var prop = {toString: function(){ return 'property'}};
var a = 0;
var b = 0;
var c = 0;
var object = {};
object.property = Math.PI;
object[symbol] = Math.PI;
weakMap.set(object, Math.PI);

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Symbol
object[symbol] = Math.random();
a += object[symbol];
ready
WeakMap
weakMap.set(object, Math.random());
b += weakMap.get(object);
ready
Property
object[prop] = Math.random();
c += object[prop];
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.