Dart is there a way to measure execution time for a small code

You can use Stopwatch to measure execution time :

Stopwatch stopwatch = new Stopwatch()..start();
doSomething();
print('doSomething() executed in ${stopwatch.elapsed}');

Dart 2:

  • Type inference
  • Optional new
final stopwatch = Stopwatch()..start();
doSomething();
print('doSomething() executed in ${stopwatch.elapsed}');

Leave a Comment