Skip to content

Instantly share code, notes, and snippets.

@homam
Created June 25, 2016 09:11
Show Gist options
  • Save homam/336d936d911a08f292feee285f5d00ac to your computer and use it in GitHub Desktop.
Save homam/336d936d911a08f292feee285f5d00ac to your computer and use it in GitHub Desktop.
const timeIt = R.curry((report, f) => (...args) => {
const t0 = Date.now()
const nArgs = R.init(args)
const callback = R.last(args)
nArgs.push((...args) => {
const t1 = Date.now()
callback(...args)
report(t1 - t0, ...args)
})
f(...nArgs)
})
const timeIt1 = timeIt(
(t, err, res) => console.log(`Log: ${err || res} produced after: ${t}`)
)
const calc = (x, y, z, callback) =>
setTimeout(() => callback(null, x * y / z), 1000)
calc(18, 7, 3, (err, res) => console.log(err || res))
timeIt1(calc)(18, 7, 3, (err, res) => console.log(err || res))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment