# How to get the index of the function in an array of functions which executed the fastest in JavaScript?

• Last Updated : 15 Jul, 2021

In this example, we will learn how to get the index of the function in an array of functions that is executed the fastest in JavaScript.

Example:

```Input: fun[] = [ hello, hello1, hello2 ]
Output: index of fastest is 0.

Explanation: Function hello execute fastest in all functions.

Input: fun[] = [ while1, while2, while3 ]
Output: index of fastest function is 2 ```

Approach: The below steps have to be followed to solve the problem:

• We will first Iterate over the given array.
• We will find the time take by each function and store it in a different array with the same index value as the function index. The time taken can be found by getting the difference in time using the performance.now() method.
• Finally, we print the minimum index by getting the minimum value of the array using the Math.min() method.

The below examples demonstrate this approach.

Example 1:

## Javascript

 ``

Output:

```The hello function takes
5.8547000009566545
The hello1 function takes
0.2459999993443489
The hello2 function takes
0.19830000028014183
Index of fastest function
2```

Example 2:

## Javascript

 ``

Output:

```Factorial of 4 is: 6
7.554999999701977
6th fibonacci no is: 8
0.22690000012516975
Power 2 to 22 mod 1e9+7 is: 221047735
0.25120000168681145
Index of fastest function: 1```

My Personal Notes arrow_drop_up