Skip to content

Instantly share code, notes, and snippets.

@Shahor Shahor/proxy.js
Created Nov 25, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.