Skip to content

Instantly share code, notes, and snippets.

@KoryNunn
Created July 9, 2015 07:13
Show Gist options
  • Select an option

  • Save KoryNunn/c6ca8ef9b40e27b0c042 to your computer and use it in GitHub Desktop.

Select an option

Save KoryNunn/c6ca8ef9b40e27b0c042 to your computer and use it in GitHub Desktop.
Native WeakMap vs es6-weak-map
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);
@KoryNunn
Copy link
Author

KoryNunn commented Jul 9, 2015

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

@KoryNunn
Copy link
Author

KoryNunn commented Jul 9, 2015

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