inline_benchmarker 1.0.0

  • README.md
  • Example
  • Installing
  • Versions
  • 42

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
  
  loginBenchmark.stop();
  Benchmarker.report();
}
Explanation of Code:
Output:
[DEFAULT] loginBenchmark: Runtime: 1000 us
Explanation of Output:

µs is an abbreviation for microseconds.

Benchmarking Loops

void calculateMethod()
{
  Benchmark calculationBenchmark = Benchmarker.generate("calculationBenchmark", autoRun: false);
  
  for (int i = 0; i < 100 ; i++)
  {
    calculationBenchmark.start();   
    // Perform calculation logic
    calculationBenchmark.stop();
  }
  
  Benchmarker.report();
}
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:

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++)
  {
    calculateLoopBenchmark.start();
    // Perform calculation logic
    calculateOtherStuffMethod();
    calculateLoopBenchmark.stop();
  }
  
  calculateMethodBenchmark.stop();
  Benchmarker.report(group: 'CALCULATION');
}

void calculateOtherStuffMethod()
{
  Benchmark calculateOtherStuffMethodBenchmark  = Benchmarker.generate("Calculate Other Stuff Benchmark", group: 'CALCULATION', indentation: 2);
  // Perform other calculation logic
  calculateOtherStuffMethodBenchmark.stop();
}
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
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:

Benchmarker.disable();
Output:
Enable benchmarks to produce a report

Info

For more info about this project, contact:

example/main.dart

import 'package:inline_benchmarker/inline_benchmarker.dart';

void main() {
  runMyStuff();
  runMyOtherStuff();
}

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

  for (int i = 0; i < 100; i++) {
    forLoopBenchmark.start();
    runMyOtherStuff();
    forLoopBenchmark.stop();
  }

  runMyStuffBenchmark.stop();

  Benchmarker.report(group: 'MAIN');
  Benchmarker.report();
}

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

  runMyOtherStuffBenchmark.stop();
}

Use this package as a library

1. Depend on it

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


dependencies:
  inline_benchmarker: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
1.0.0 Sep 4, 2018 Go to the documentation of inline_benchmarker 1.0.0 Download inline_benchmarker 1.0.0 archive
0.1.1 Aug 14, 2015 Go to the documentation of inline_benchmarker 0.1.1 Download inline_benchmarker 0.1.1 archive
0.1.0 Aug 14, 2015 Go to the documentation of inline_benchmarker 0.1.0 Download inline_benchmarker 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
42
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:inline_benchmarker/inline_benchmarker.dart.

Maintenance issues and suggestions

Maintain CHANGELOG.md. (-20 points)

Changelog entries help clients to follow the progress in your code.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

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