dart

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


I've made some snippet involving parsing a html and wants to know if the code runs slow or not, is this doable?


Solution

  • You can use Stopwatch to measure execution time :

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

    Dart 2:

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