The Dart project benchmark harness is the recommended starting point when building a benchmark for Dart.
You can read more about Benchmarking the Dart VM.
By default, the reported runtime is not for a single call to run()
, but for
the average time it takes to call run()
10 times. The
benchmark harness executes a 10-call timing loop repeatedly until 2 seconds
have elapsed; the reported result is the average of the runtimes for each
loop.
If you are running the same benchmark, on the same machine, running the same OS, the reported run times can be carefully compared across runs. Carefully because there are a variety of factors which could cause error in the run time, for example, the load from other applications running on your machine could alter the result.
Comparing the run time of different benchmarks is not recommended. In other words, don't compare apples with oranges.
BenchmarkBase
class that all new benchmarks should extend
1. Add the following to your project's pubspec.yaml
dependencies:
benchmark_harness: any
2. Install pub packages
pub install
3. Add the following import:
import 'package:benchmark_harness/benchmark_harness.dart';
4. Create a benchmark class which inherits from BenchmarkBase
// Import BenchmarkBase class.
import 'package:benchmark_harness/benchmark_harness.dart';
// Create a new benchmark by extending BenchmarkBase
class TemplateBenchmark extends BenchmarkBase {
const TemplateBenchmark() : super("Template");
static void main() {
new TemplateBenchmark().report();
}
// The benchmark code.
void run() {
}
// Not measured setup code executed prior to the benchmark runs.
void setup() { }
// Not measures teardown code executed after the benchark runs.
void teardown() { }
}
main() {
// Run TemplateBenchmark
TemplateBenchmark.main();
}
Template(RunTime): 0.1568472448997197 us.
This is the average amount of time it takes to run run()
10 times.
µs is an abbreviation for microseconds.
This package is carefully curated by the Dart team to exact specifications. Please open an issue with any proposed changes, before submitting a Pull Request.
Add this to your package's pubspec.yaml file:
dependencies:
benchmark_harness: ^1.0.5
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.
Now in your Dart code, you can use:
import 'package:benchmark_harness/benchmark_harness.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
1.0.5 | Jul 26, 2018 |
|
|
1.0.4 | Feb 14, 2014 |
|
|
1.0.3 | Jan 10, 2014 |
|
|
1.0.2 | Dec 20, 2012 |
|
|
1.0.1 | Nov 26, 2012 |
|
|
1.0.0 | Nov 20, 2012 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
64
|
Health:
Code health derived from static analysis.
[more]
|
99
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
84
|
Overall:
Weighted score of the above.
[more]
|
78
|
We analyzed this package on Feb 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter, web, other
No platform restriction found in primary library
package:benchmark_harness/benchmark_harness.dart
.
Document public APIs. (-1 points)
19 out of 19 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.
Fix lib/src/benchmark_base.dart
. (-0.50 points)
Analysis of lib/src/benchmark_base.dart
reported 1 hint:
line 10 col 57: Use =
to separate a named parameter from its default value.
The package description is too short. (-16 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.
Maintain an example.
None of the files in the package's example/
directory matches known example patterns.
Common filename patterns include main.dart
, example.dart
, and benchmark_harness.dart
. Packages with multiple examples should provide example/README.md
.
For more information see the pub package layout conventions.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.0.0-dev <3.0.0 | ||
Dev dependencies | |||
build_runner | ^0.9.0 | ||
build_web_compilers | ^0.4.0 | ||
mockito | ^3.0.0 | ||
path | ^1.1.0 | ||
test | ^1.0.0 |