Skip to content

Instantly share code, notes, and snippets.

@anteriovieira
Forked from ericelliott/profile.js
Created November 28, 2017 22:18
Show Gist options
  • Save anteriovieira/bce78d8432ede4b2bd0258dd9c3613d7 to your computer and use it in GitHub Desktop.
Save anteriovieira/bce78d8432ede4b2bd0258dd9c3613d7 to your computer and use it in GitHub Desktop.
A good enough profile script to compare two versions of a fibonacci generator.
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