xxxxxxxxxx
// Start the timer
console.time('timer');
// Your code or function here
for (let i = 0; i < 1000000; i++) {
// Some time-consuming task
}
// Stop the timer and log the elapsed time
console.timeEnd('timer');
xxxxxxxxxx
var startTime = performance.now();
alert('Run some function here');
var endTime = performance.now();
var totalTime=endTime-startTime;// time took to run in milliseconds
alert('Total time:'+totalTime +'ms');
xxxxxxxxxx
// Measure time in milliseconds
const startTime = Date.now();
// Your code or operations here...
const endTime = Date.now();
const elapsedTime = endTime - startTime;
console.log(`Elapsed time: ${elapsedTime} ms`);
xxxxxxxxxx
console.time("timer"); //start time with name = timer
console.timeEnd("timer"); //end timer and log time difference