Javascript console.timeEnd() Method

Introduction

How long does it take to perform a for-loop 100.000 times:

Press F12 on your keyboard to view the result in the console view.

Time the number of milliseconds it takes to perform a for-loop a hundred thousand times.

the console.time() method starts the timer and the console.timeEnd() method ends the timer and writes the result in the console view.

View in separate window

<!DOCTYPE html>
<html>
<body>
<script>

console.time();
for (i = 0; i < 100000; i++) {
  // some code//from   w w w  .  j  ava  2  s  .  c om
}
console.timeEnd();

</script>
</body>
</html>

The console.timeEnd() method ends a timer, and writes the result in the console view.

Use the label parameter to specify which timer to end.

console.timeEnd(label);

Parameter Values

Parameter Type Description
label String Optional. The name of the timer to end



PreviousNext

Related