performance check javascript code example

Example 1: test load function benchmark javascript

var iterations = 1000000;
console.time('Function #1');
for(var i = 0; i < iterations; i++ ){
    functionOne();
};
console.timeEnd('Function #1')

console.time('Function #2');
for(var i = 0; i < iterations; i++ ){
    functionTwo();
};
console.timeEnd('Function #2')

Example 2: performance javascript

const t0 = performance.now();
// doSomething();
const t1 = performance.now();
console.log(`Call to doSomething took ${t1 - t0} milliseconds.`);

Example 3: javascript performance

var i;
for (i = 0; i < arr.length; i++) {