inline_benchmarker 1.0.0

About #

InlineBenchmarker is an easy to use inline benchmarking system.
The goal of inline benchmarking is to help you find bottle-necks in your application, rather than to benchmark abstract units.
Therefor Dart's benchmark harness library would probably be better suited.
Inline benchmarks can be used in projects that are otherwise hard to benchmark (perhaps because they are too much of a spaghetti), or to monitor alghorithms on how they respond with production processes and data.

How To: Using The Benchmarker #

Benchmarking Methods #

void loginMethod()
  Benchmark loginBenchmark = Benchmarker.generate("loginBenchmark");
  // Perform login logic
Explanation of Code: #
  • loginBenchmark is the name of the benchmark
  •; will print out the results of the benchmark
Output: #
[DEFAULT] loginBenchmark: Runtime: 1000 us
Explanation of Output: #
  • [DEFAULT] stands for the group the benchmark belongs to
  • 1000 us is how long the benchmark took to run

µs is an abbreviation for microseconds.

Benchmarking Loops #

void calculateMethod()
  Benchmark calculationBenchmark = Benchmarker.generate("calculationBenchmark", autoRun: false);
  for (int i = 0; i < 100 ; i++)
    // Perform calculation logic
Explanation of Code: #
  • Setting autoRun to false will prevent the benchmark from running instantly.
  • Benchmarks can be started manually using the start() method
Output: #
[DEFAULT] calculationBenchmark:
› (1/100) Runtime: 10 us
› (2/100) Runtime: 10 us
› (3/100) Runtime: 10 us
› (100/100) Runtime: 10 us

Explanation of Output: #
  • (1/100) is which iteration was benchmarked

Using Group and Indentation Parameters #

For more complex applications, which combine nested methods and loops, it might be useful to format the output text using the group and indentation parameters.

void calculateMethod()
  Benchmark calculateMethodBenchmark  = Benchmarker.generate("Calculation Benchmark", group: 'CALCULATION');
  Benchmark calculateLoopBenchmark    = Benchmarker.generate("Calculation Loop Benchmark", group: 'CALCULATION', indentation: 1, autoStart: false);
  for (int i = 0; i < 100 ; i++)
    // Perform calculation logic
  calculateMethodBenchmark.stop(); 'CALCULATION');

void calculateOtherStuffMethod()
  Benchmark calculateOtherStuffMethodBenchmark  = Benchmarker.generate("Calculate Other Stuff Benchmark", group: 'CALCULATION', indentation: 2);
  // Perform other calculation logic
Explanation of Code: #
  • The group parameter will group benchmarks together in the output console.
  • When no group is specified, a 'DEFAULT' group will be created
  • The indentation parameter will indent the output with the number of tabs specified
  • 'CALCULATION'); will only report the benchmark specified by the group parameter
Output: #
[CALCULATION] Calculation Benchmark: Runtime: 10000 us
  [CALCULATION] Calculation Loop Benchmark:
  › (1/100) Runtime: 10 us
    [CALCULATION] Calculate Other Stuff Benchmark: Runtime: 10 us
  › (2/100) Runtime: 10 us
    [CALCULATION] Calculate Other Stuff Benchmark: Runtime: 10 us
  › (3/100) Runtime: 10 us
    [CALCULATION] Calculate Other Stuff Benchmark: Runtime: 10 us
  › (100/100) Runtime: 10 us
    [CALCULATION] Calculate Other Stuff Benchmark: Runtime: 10 us

How To: Disabling Benchmarks #

When you are running in production mode, you probably don't want the benchmarks running constantly. A better option would be to give your application the ability to enable/disable benchmarks (perhaps by passing a URL parameter, in the case of a web application).

Disabling benchmarks is very easy:

Output: #
Enable benchmarks to produce a report

Info #

For more info about this project, contact:


import 'package:inline_benchmarker/inline_benchmarker.dart';

void main() {

void runMyStuff() {
  Benchmark runMyStuffBenchmark =
      Benchmarker.generate('runMyStuff', group: 'MAIN');
  Benchmark forLoopBenchmark = Benchmarker.generate('forLoop', autoRun: false);

  for (int i = 0; i < 100; i++) {

  runMyStuffBenchmark.stop(); 'MAIN');;

void runMyOtherStuff() {
  Benchmark runMyOtherStuffBenchmark =
      Benchmarker.generate('runMyOtherStuff', indentation: 1, group: 'MAIN');


Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  inline_benchmarker: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:inline_benchmarker/inline_benchmarker.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Fix lib/src/api/benchmarker.dart. (-3.45 points)

Analysis of lib/src/api/benchmarker.dart reported 7 hints, including:

line 10 col 33: Unnecessary new keyword.

line 26 col 37: Use = to separate a named parameter from its default value.

line 26 col 57: Use = to separate a named parameter from its default value.

line 27 col 27: Unnecessary new keyword.

line 34 col 9: Unnecessary new keyword.

Fix lib/src/api/benchmark.dart. (-1 points)

Analysis of lib/src/api/benchmark.dart reported 2 hints:

line 37 col 22: Unnecessary new keyword.

line 71 col 27: Unnecessary new keyword.

Maintenance issues and suggestions

Provide a file named (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Package is getting outdated. (-44.11 points)

The package was last published 75 weeks ago.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0