symbol-vs-weakmap

JavaScript performance comparison

Revision 4 of this test case created

Info

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

Preparation code

<script>

var symbol = new Symbol();
var weakMap = new WeakMap();
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

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Symbol
object[symbol] = Math.random();
a += object[symbol];
pending…
WeakMap
weakMap.set(object, Math.random());
b += weakMap.get(object);
pending…
Property
object.property = Math.random();
c += object.property;
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment