function trace(o, m) { let original = o[m]; o[m] = function (...args) { console.log(new Date(), 'Entering', m); let result = original.apply(this, args); console.log(new Date(), 'Exiting:', m); return result; } } const m = { m: 1 } const a = { a: 'a' } function benchmark(n) { let sum = 0; for (let i = 1; i <= n; i++) sum += i; return sum; } console.log('traceObj:', trace(m, a)(100000));