1var startTime = performance.now();
2
3alert('Run some function here');
4
5var endTime = performance.now();
6var totalTime=endTime-startTime;// time took to run in milliseconds
7
8alert('Total time:'+totalTime +'ms');
1var t0 = performance.now();
2
3doSomething(); // <---- The function you're measuring time for
4
5var t1 = performance.now();
6console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.");
1var t0 = performance.now()
2
3doSomething() // <---- The function you're measuring time for
4
5var t1 = performance.now()
6console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.")
1const { JSDOM } = require("jsdom");
2const { window } = new JSDOM();
3
4var start = window.performance.now();
5
6// task starts
7for (var i = 0; i < 100000000;i++);
8// task ends
9
10var end = window.performance.now();
11console.log(`Execution time: ${end - start} ms`);