Member-only story
Add Quick Profiling to your JavaScript and TypeScript Code
Many times we come across a situation where we need to monitor the execution time of the functions or the code that we write. Be it an API respo nding slow or any function that is taking a longer time to complete its execution.
In this article we will see how we can monitor the time taken by a function or even a line of code using the JavaScript in-built performance module.
If you are using TypeScript, the same module can be used there as well.
In case, you are using Object Oriented approach in TypeScript, I have a bonus tip for you at the end.
Let’s start with the file JavaScript first.
Here is the output of the code:
What we have seen so far?
- The performance module starts a timer as soon as the execution of the application starts.
- At any given time, we can know the elapsed time since execution by using performance.now() function.
- To calculate the execution time…