How Long Does a Function Take: Measuring Execution Time
·
189 words
·
1 minute read
We often need to measure execution time in programming, as it helps us understand the programs we’re working with and knowing where potential bottlenecks are occurring.
In Go, we are able to use the time
package and the defer
keyword to run our time tracking function at the end of our long function. The parameters will be calculated at the beginning of the function (thus freezing the start time). Once the deferred function is running, all we need to do is show the difference in start time and current time.
|
|
Example: