Created
September 19, 2012 20:33
-
-
Save devdazed/3752095 to your computer and use it in GitHub Desktop.
Harmony Proxy Benchmark
This file contains 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 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'); |
This file contains 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
$ 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