Skip to content

Instantly share code, notes, and snippets.

@willmendesneto
Last active March 29, 2021 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willmendesneto/41985f16808602e62510f3c994edebbc to your computer and use it in GitHub Desktop.
Save willmendesneto/41985f16808602e62510f3c994edebbc to your computer and use it in GitHub Desktop.
perf-marks example using profiler method
import { profiler } from 'perf-marks/profiler';
const marker = 'my-marker';
const someExpensiveMemoryAndTimeTask = () => 1 + 1;
// Just need to wrap your function with `profiler()` method and that's it!
// Easy peasy, lemon squeezy! 🍋
profiler(async () => {
return new Promise((resolve) => {
setTimeout(() => {
setTimeout(() => {
resolve(someExpensiveMemoryAndTimeTask());
}, 1000);
}, 2000);
});
}, marker).then(result => console.log(result));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment