public
Created

Harmony Proxy Benchmark

  • Download Gist
proxy_bench.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
var noop = function(){};
var obj = {
'1':function(){ console.log(1) },
'10':function(){ console.log(10) },
'100':function(){ console.log(100) },
'1000':function(){ console.log(1000) },
'10000':function(){ console.log(10000) }
};
 
console.time('checking');
for(var i = 0; i < 10000000; i += 1){
if(i in obj){
obj[i]();
} else {
noop();
}
}
console.timeEnd('checking');
 
var proxy = Proxy.create({
getOwnPropertyDescriptor: function(name){ return Object.getOwnPropertyDescriptor(obj); },
getPropertyDescriptor: function(name){ return Object.getOwnPropertyDescriptor(obj); },
getOwnPropertyNames: function(){ return Object.getOwnPropertyNames(obj); },
getPropertyNames: function(){ return Object.getOwnPropertyNames(obj); },
get: function(recv, name){ return obj[name] || noop; }
}, obj);
 
console.time('proxy');
for(var i = 0; i < 10000000; i += 1){
proxy[i]();
}
console.timeEnd('proxy');
results
1 2 3 4 5 6 7 8 9 10 11 12 13
$ node --harmony-proxies proxy_bench.js
1
10
100
1000
10000
checking: 418ms
1
10
100
1000
10000
proxy: 4680ms

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.