-
-
Save anteriovieira/f1cf88bb5f781a2571f5fa68ab1d3ae1 to your computer and use it in GitHub Desktop.
A good enough profile script to compare two versions of a fibonacci generator.
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
import iterativefib from 'iterativefib'; | |
import memofib from 'memofib'; | |
import range from 'test/helpers/range'; | |
const nsTime = (hrtime) => hrtime[0] * 1e9 + hrtime[1]; | |
const profile = () => { | |
const numbers = 79; | |
const msg = `Profile with ${ numbers } numbers`; | |
const fibGen = iterativefib(); | |
const fibStart = process.hrtime(); | |
range(1, numbers).map(() => fibGen.next().value); | |
const fibDiff = process.hrtime(fibStart); | |
const memoGen = memofib(); | |
const memoStart = process.hrtime(); | |
range(1, numbers).map(() => memoGen.next().value); | |
const memoDiff = process.hrtime(memoStart); | |
const original = nsTime(fibDiff); | |
const memoized = nsTime(memoDiff); | |
console.log(msg); | |
console.log(` | |
original: ${ original }ns | |
memoized: ${ memoized }ns | |
`); | |
}; | |
profile(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment