execution_timer 1.1.0+13
execution_timer: ^1.1.0+13 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.
- Use the
ExecutionWatchandExecutionTimerto 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 - Use the
TimeKeeper.measurefunction:// 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));