Skip to content

Instantly share code, notes, and snippets.

@arnaudrenaud
Last active April 24, 2024 14:10
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 arnaudrenaud/fd560bec78a133d2c3b1bfffb76195a7 to your computer and use it in GitHub Desktop.
Save arnaudrenaud/fd560bec78a133d2c3b1bfffb76195a7 to your computer and use it in GitHub Desktop.
Measure execution time in Node.js
const { performance } = require("perf_hooks");
const start1 = performance.now();
JSON.stringify({ emailAddress: "arnaud.renaud@gmail.com" });
const end1 = performance.now();
console.log(
`Time taken to execute JSON.stringify function is ${end1 - start1}ms.`
);
const start2 = performance.now();
JSON.parse('{"emailAddress": "arnaud.renaud@gmail.com"}');
const end2 = performance.now();
console.log(
`Time taken to execute JSON.parse function is ${end2 - start2}ms.`
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment