Created
November 25, 2016 09:47
-
-
Save Shahor/73e2758969a622fc713864a6a307464d to your computer and use it in GitHub Desktop.
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
let Process = require('process') | |
let obj = { | |
toto () { | |
return 42 | |
} | |
} | |
function *range(s, e) { | |
for (; s < e; s++) { | |
yield s | |
} | |
} | |
let proxy = new Proxy(obj, { | |
get (target, method) { | |
return (...args) => { | |
return target[method].apply(target, ...args) | |
} | |
} | |
}) | |
const ITERATIONS = 1000000 | |
console.time('call function directly') | |
for (let r of range(0, ITERATIONS)) { | |
obj.toto() | |
} | |
console.timeEnd('call function directly') | |
console.time('call function via proxy') | |
for (let r of range(0, ITERATIONS)) { | |
proxy.toto() | |
} | |
console.timeEnd('call function via proxy' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment