Timing asynchronous functions in JavaScript ES6

calc(arg, (err, res) => console.log(err || res))
const t0 = Date.now()
calc(arg, (err, res) => {
const t1 = Date.now()
console.log(`Log: time: ${t1 = t0}`)
console.log(err || res)
})
timeIt(calc)(arg, (err, res) => console.log(err || res))
  • report: a function that will be called with the profiling result
  • f: the async function that we’re profiling
timeIt1(calc)(18, 7, 3, (err, res) => console.log(err || res))
timeIt(
(time, ...result) => // report callback: log the time
, asyncFunc
)(
parameters…,
(...result) => // result of the async function
)
const f = R.curry((x, y) => x + y)
f(1, 10) // == 11
f(1)(10) // == 11
const plus1 = f(1)
plus1(10) // == 11
(...args) => {
const t1 = Date.now()
callback(...args)
report(t1 — t0, ...args)
}

--

--

--

Me: http://homam.me/ | My code: https://github.com/homam/

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Homam

Homam

Me: http://homam.me/ | My code: https://github.com/homam/

More from Medium

Angular with Jest Testing

The case against Non Null Assertion Operator !

React.js Basics — Part 2 (for starters and Angular Developers)

TypeScript vs JavaScript