Table of Contents


Provides a simple way to time parts of code as they execute in real, clock, time.

Using the Library

Add the repo to your Dart pubspec.yaml file.

  execution_timer: <<version>> 

Then run...

dart pub get

By default, the timing is enabled in debug mode but disabled in production mode. To change this set TimeKeeper.enabled to be true or false. Since this is not a Flutter library, it can be used in any Dart base application, but it cannot detect Profile mode vs Debug.

There are two ways to perform a time measurement.

  1. Use the ExecutionWatch and ExecutionTimer to manually measure your timing:
    // This option will be more performant for loops like the following...
    final watch = ExecutionWatch(group: 'myGroup', name: 'myTimerName');
    for (var i = 0; i < someCount; i++) {
      final timer = watch.start();
      // do something worth measuring
    // each iteration from the loop will be individually timed
  2. Use the TimeKeeper.measure function:
    // This option may be easier for timing long-ish running units of work with
    // return values.
    final result = await TimeKeeper.measure<X>(
      (timer) async {
        X result;
        // doSomething that assigns X to the result
        return result;
      group: 'myOptionalGroupName',

When you need the results, you can get them from:

final timings = TimeKeeper.toJson();

print(const JsonEncoder.withIndent('  ').convert(timings));