HTML | DOM console.timeEnd() Method

The console.timeEnd() method in HTML is used to end a timer started by the console.time() method. This can be used to calculate the time of certain operations for testing purposes.

Syntax:

console.timeEnd( label )

Parameters: This method accepts single parameter label which is optional. It is used to specify the label of the timer to stop.



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        DOM console.timeEnd() Method
    </title>
</head>
  
<body>
    <h1 style="color: green">
            GeeksforGeeks
        </h1>
  
    <p>DOM console.timeEnd() Method</p>
  
    <p>
        Clicking the START TIMER button executes
        console.time() to start the timer.<br
        Clicking the END TIMER button executes
        console.timeEnd() to end the timer.
    </p>
  
    <button onclick="start_timer()">
        Start Timer
    </button>
  
    <button onclick="end_timer()">
        End Timer
    </button>
  
    <script>
        // Function to start timer
        function start_timer() {
            console.log('timer started');
            console.time();
        }
  
        // Function to end timer
        function end_timer() {
            console.timeEnd();
        }
    </script>
</body>
  
</html>      

chevron_right


Output:
timeEnd example 1
Console View:
timeEnd example 1 console

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        DOM console.timeEnd() Method
    </title>
</head>
  
<body>
    <h1 style="color: green">
            GeeksforGeeks
        </h1>
  
    <p>DOM console.timeEnd() Method</p>
  
    <p>
        Clicking the START TIMER button starts
        the timer with label 'timer 1'.<br>
        Clicking the END TIMER button ends the
        timer with label 'timer 1'.
    </p>
  
    <button onclick="start_timer_one()">
        Start Timer 1
    </button>
  
    <button onclick="end_timer_one()">
        End Timer 1
    </button>
  
    <p>
        Clicking the START TIMER button starts 
        the timer with label 'timer 2'.<br
        Clicking the END TIMER button ends the
        timer with label 'timer 2'.
    </p>
  
    <button onclick="start_timer_two()">
        Start Timer 2
    </button>
  
    <button onclick="end_timer_two()">
        End Timer 2
    </button>
  
    <script>
        // Start first timer
        function start_timer_one() {
            console.log('timer 1 started');
            console.time('timer 1');
        }
  
        // End first timer
        function end_timer_one() {
            console.timeEnd('timer 1');
        }
  
        // Start second timer
        function start_timer_two() {
            console.log('timer 2 started');
            console.time('timer 2');
        }
  
        // End second timer
        function end_timer_two() {
            console.timeEnd('timer 2');
        }
    </script>
</body>
  
</html>

chevron_right


Output:
timeEnd example 2
Console View:
timeEnd example 2 console

Supported Browsers: The browser supported by console.timeEnd() Method are listed below:

  • Google Chrome
  • Internet Explorer 11.0
  • Firefox 10.0
  • Opera
  • Safari 4.0


My Personal Notes arrow_drop_up

Technical Writer Lets have an update

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.