Created
June 25, 2016 09:11
-
-
Save homam/336d936d911a08f292feee285f5d00ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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