S.no | Contents-topics |
---|---|
1 | What is time compexity |
2 | Calculate time taken by function |
3 | Calculate total laoding time by page |
4 | Total excution time in function |
Time Complexity means time taken to complete a task whether the task is to calculate time for excution of a function , loading time of a page or may be sometimes like total time for getting data from backend or using some apis .
Here we are considering function by showing how to calculate time complexity by a function like as shown we are using startTime and endTime variables to calculate the time difference in a function
code for cal time: Copy
Also read:READ A LOCAL TEXT FILE USING JAVASCRIPT
Here we are calculating total laoding time by page like sometimes working on some projcts where we want to calculate the total time taken by laoding a page , here is how we can calculate by by intializing startTime variable in the starting of the page and at the end of the page we are usning endTime variable so to calculate the time difference of laoding page
code for time loading page: Copy
So here we are using simple registration template to check how much time it will take to load the page in console it shows the start = 1761.19 and end = 1892.30 so the total time is 131.10 in milliseconds.
But if you want to check the total time execution of function then use this , as we are using a ajax request which calclute the time from the data that comes from backend request
code for cal time in function Copy
So here we are submitting a form using ajax request and check how much time it takes in console.
0 Comments (Please let us know your query)