Skip to content

Instantly share code, notes, and snippets.

@Shahor
Created November 25, 2016 09:47
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 Shahor/73e2758969a622fc713864a6a307464d to your computer and use it in GitHub Desktop.
Save Shahor/73e2758969a622fc713864a6a307464d to your computer and use it in GitHub Desktop.
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