In this blog, I will explain How to get function executing time in the flutter.
Introduction :
Dart offers a method to determine the measured (test) time needed to complete a function in this blog article.
To optimise performance, we may need to know the runtime when profiling Dart programmes.
spent assisting developers in identifying process problems.
Darts for time. In Flutter, calculate the execution time.
You may also check our Flutter app development page.
Measure execution time in dart :
A StopWatch class that determines measuring time is offered by Dart. Get function executing time by using the start method, you may start StopWatch. To halt the execution, use the stop() function. It has a variety of elapsed attributes to return the execution time.
elapsed -> Return Duration Object that returns elapsed microsecond
elapsedTicks -> The number of ticks exceeded
elapsedMilliseconds -> Returns elapsed milliseconds
elapsedMicroseconds -> Returns elapsed microseconds
Code :
1 2 3 4 5 6 7 8 9 10 11 |
getDataFunction() { print("Welcome To Webkul"); } void main() { final stopwatch = Stopwatch()..start(); getDataFunction(); stopwatch.stop(); print('Function Execution Time : ${stopwatch.elapsed}'); } |
Output :
Web application tack execution time :
A Web application that delivers more resolution time (nanoseconds, etc.) can utilise window.performance.now(). Microseconds are returned in double format.
It provides the amount of time that has passed since the genesis. Here is a use illustration
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import 'dart:html'; getDataFunction() { print("Welcome to webkul"); } void main() { var execution_timer1 = window.performance.now(); print(execution_timer1); // 118.40000000037253 getDataFunction(); var execution_timer2 = window.performance.now(); print(execution_timer2); // 118.59999999962747 print('Function execute time : ${execution_timer2 - execution_timer1}'); } |
OutPut :
Conclusion:
In this article, we have explained How to get function executing time in the flutter.
Thanks for reading this article
For more interesting blogs check here