execution_timer 1.1.0+7 copy "execution_timer: ^1.1.0+7" to clipboard
execution_timer: ^1.1.0+7 copied to clipboard

A library that makes it easy to determine how long snippets of code take to execute in real clock time.

execution_timer #

Table of Contents

Introduction #

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.

dependencies:
  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
      timer.stop();
    }
    
    // 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>(
      'myTimerName',
      (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));
4
likes
140
pub points
73%
popularity

Publisher

unverified uploader

A library that makes it easy to determine how long snippets of code take to execute in real clock time.

Documentation

API reference

License

MIT (license)

More

Packages that depend on execution_timer