Skip to content

Instantly share code, notes, and snippets.

@devdazed
Created September 19, 2012 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdazed/3752095 to your computer and use it in GitHub Desktop.
Save devdazed/3752095 to your computer and use it in GitHub Desktop.
Harmony Proxy Benchmark
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');
$ node --harmony-proxies proxy_bench.js
1
10
100
1000
10000
checking: 418ms
1
10
100
1000
10000
proxy: 4680ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment