- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
In this tutorial, we will be learning how to execute function and calculate time taken by the function to execute and we will print the index of that function which will take less time to execute.
Before moving to our problem let’s get to know about procedure to calculate execution time of a function.
We use performance.now() method to check the performance of the code and we can check the execution time of our current executing function using this method, performance.now() method returns calculated time in milliseconds. So we store starting time before function calling and again we calculate the time after function execution has been finished.
Note − You may get different result in the output.
Now let’s come to our main problem to get the index of fastest function.
Step 1 − Store the function names in the array.
Step 2 − Traverse through the whole array.
Step 3 − Calculate the starting time before calling the function.
Step 4 − Call the current function.
Step 5 − Calculate the ending time after execution of the function.
Step 6 − Calculate the difference of ending time ad starting time of the function.
The output we get here is total time taken by all the four functions and we store the index in the TimeTaken_byFunction array and here the fastest time is the minimum time.
So, this was the procedure to check and get the index of the function which executes faster.
- How to get the current index of an array while using forEach loop in Kotlin?
- How to get the index of an array element in older versions on MongoDB?
- How do I get the index of an item in Tkinter.Listbox?
- How to return the index of first unique character without inbuilt functions using C#?