Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .measure() to measure performance time #5

Open
lisaychuang opened this issue Aug 2, 2018 · 0 comments
Open

Add .measure() to measure performance time #5

lisaychuang opened this issue Aug 2, 2018 · 0 comments
Labels
enhancement New feature or request

Comments

@lisaychuang
Copy link
Owner

logger.measure should return a similar function, that takes a timestamp before and after invoking the original function, printing the time (colorfully) it took to run

EXAMPLE:

function measureFunction(fn) {
  return function () {
    const start = performance.now();
    const result = fn.call(this, arguments);
    const stop = performance.now();
    console.log('' + fn.name + '(...) took ' + (stop - start) + 'ms to run');
    return result;
  };
}

function stringifyAndUndo(obj) {
  let objAsString = JSON.stringify(obj);
  let backToObj = JSON.parse(objAsString);
  return backToObj;
}

const measuredFunction = measureFunction(stringifyAndUndo);
const result = measuredFunction(
  { hello: 'world', travelTo: 'mars' }
);
@lisaychuang lisaychuang added the enhancement New feature or request label Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant