Created
July 9, 2015 07:13
-
-
Save KoryNunn/c6ca8ef9b40e27b0c042 to your computer and use it in GitHub Desktop.
Native WeakMap vs es6-weak-map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var NativeWeakMap = WeakMap; | |
| global.WeakMap = null; | |
| var PolyWeakMap = require('es6-weak-map'); | |
| var itterations = 1000000, | |
| key = {}; | |
| var nativeWM = new NativeWeakMap(); | |
| nativeWM.set(key, 1); | |
| var start = Date.now(); | |
| for(var i = 0; i < itterations; i++){ | |
| nativeWM.get(key); | |
| } | |
| console.log(Date.now() - start); | |
| var polyWM = new PolyWeakMap(); | |
| polyWM.set(key, 1); | |
| var start = Date.now(); | |
| for(var i = 0; i < itterations; i++){ | |
| polyWM.get(key); | |
| } | |
| console.log(Date.now() - start); |
Author
Author
The above results are for io.js
In chrome 43.0.2357.125 (64-bit), the polyfill is always slower:
1000:
Native: 1,
Poly: 2
100000:
Native: 17,
Poly: 46
10000000:
Native: 1068,
Poly: 4205
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On my pc:
Native: 140
Poly: 307
Poly is faster than native for small iterations though (1000):
Native: 7
Poly: 1
Massive iterations (10000000):
Native: 1203
Poly: 3496