Option 1:
1. Go to Developer Console.
2. Navigate to Debug –> View Log Panels…
3. Select Execution Stack.
Sample Code with SOQL to execute in Anonymous Window:
List < Account > listAccount = [
SELECT Id, Name, Website
FROM Account
WHERE Name = 'InfallibleTechie'
];
Note:
Duration is in Milliseconds. So, convert it to Seconds by dividing it by 1000.
Option 2:
1. Go to Debug –> Change Log Levels… in Developer Console.
2. Click Add/ Change.
3. Set Profiling to Finest.
4. Execute the query in the anonymous window.
5. You can find the execution time in the log.
Note:
In the above approach, it gives the overall run time or execution time of the Apex. So, don’t add additional apex coding.