pub repository
mirror.p-hatan.irbenchmark_harness
2.2.0The official Dart project benchmark harness.
Readme
Dart CI pub package package publisher
The Dart project benchmark harness is the recommended starting point when building a benchmark for Dart.
Interpreting Results
By default, the reported runtime in BenchmarkBase is not for a single call to
run(), but for the average time it takes to call run() 10 times for
legacy reasons. 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. This behavior will change in a future major version.
Benchmarks extending BenchmarkBase can opt into the reporting the average time
to call run() once by overriding the exercise method:
@override
void exercise() => run();
AsyncBenchmarkBase already reports the average time to call run() once.
Comparing Results
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.
Features
BenchmarkBaseclass that all new benchmarks shouldextend.AsyncBenchmarkBasefor asynchronous benchmarks.- Template benchmark that you can copy and paste when building new benchmarks.
Getting Started
1. Add the following to your project's pubspec.yaml
dependencies:
benchmark_harness: any
2. Install pub packages
dart pub install
3. Add the following import:
import 'package:benchmark_harness/benchmark_harness.dart';
4. Create a benchmark class which inherits from BenchmarkBase or
AsyncBenchmarkBase.
Example
Create a dart file in the
benchmark/
folder of your package.
// 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() {
const TemplateBenchmark().report();
}
// The benchmark code.
@override
void run() {}
// Not measured setup code executed prior to the benchmark runs.
@override
void setup() {}
// Not measured teardown code executed after the benchmark runs.
@override
void teardown() {}
// To opt into the reporting the time per run() instead of per 10 run() calls.
//@override
//void exercise() => run();
}
void main() {
// Run TemplateBenchmark
TemplateBenchmark.main();
}
Output
Template(RunTime): 0.1568472448997197 us.
This is the average amount of time it takes to run run() 10 times for
BenchmarkBase and once for AsyncBenchmarkBase.
µs is an abbreviation for microseconds.
Contributions
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.
Changelog
2.2.0
- Change measuring algorithm in
BenchmarkBaseto avoid calling stopwatch methods repeatedly in the measuring loop. This makes measurement work better forrunmethods which are small themselves.
2.1.0
- Add AsyncBenchmarkBase.
2.0.0
- Stable null safety release.
2.0.0-nullsafety.0
- Opt in to null safety.
1.0.6
- Require at least Dart 2.1.
1.0.5
- Updates to support Dart 2.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add benchmark_harnesspubspec.yaml
name: benchmark_harness
version: 2.2.0
description: The official Dart project benchmark harness.
repository: https://github.com/dart-lang/benchmark_harness
environment:
sdk: '>=2.12.0 <3.0.0'
dev_dependencies:
build_runner: ^2.0.0
build_web_compilers: ^3.0.0
lints: ^1.0.0
path: ^1.8.0
test: ^1.16.0
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 1.0.0 | 2012-11-20T20:35:57.470500Z | Download | c1b39858cd0c644f2e77392000bb7e113f45ab7fe43fd9c15cd85294672e5208 |
| 1.0.1 | 2012-11-26T23:35:52.164560Z | Download | 12f16523a9c17a0d01d6eabd453e7326c6abf26b02a117a6eee1bde71a420f7c |
| 1.0.2 | 2012-12-20T15:32:37.592300Z | Download | 806298d7f0cad8ffdd715a895cf1f7b151467b71643bc80724e5f05171eabb87 |
| 1.0.3 | 2014-01-10T22:18:23.017320Z | Download | 47e42ab30e48c056c5e603d4d15cc887ce48470584cdaec25f202adb31aef42c |
| 1.0.4 | 2014-02-14T00:59:26.997070Z | Download | 992f666f3412d7c1c6fd3de835be43259213c20e702cbf98106cd0feeb4e96d1 |
| 1.0.5 | 2018-07-26T18:22:56.907758Z | Download | 811240744c8065bdfb5b95bea83a1b565acdf73bfc29bcadb590d66dd7687c4c |
| 2.0.0-nullsafety.0 | 2020-11-10T23:36:44.597010Z | Download | 72ea8bcf1d71764571cc72969a7187123e15becc528dbba11d53ad9f5c86df84 |
| 2.0.0 | 2021-02-05T20:58:47.672178Z | Download | e8e153466b38af37038a23a94c94618b864038f4163156f7d06b8b7ebfda76b0 |
| 2.1.0 | 2022-05-03T12:16:52.401589Z | Download | 72b770741a03b657bf830bda92682f8e1c8d1c459ff2859168f0cb737d00da0d |
| 2.2.0 | 2022-07-06T10:54:03.351406Z | Download | 200beeddb5e8b3611ebb0bc8a730d63967afc3c9a5898791245eb46712a83a24 |
| 2.2.1 | 2023-02-02T16:09:31.837887Z | Download | 683bdcf9d96ec6f244d383a8b07f329fe64f0d3ef51739b82417ce904dd29d03 |
| 2.2.2 | 2023-05-08T23:55:08.922857Z | Download | a12bc021ec45c05f60ad65a6cec1be881d4d84842699b2c4f4aa59f1089de242 |
| 2.2.3 | 2024-04-19T10:55:50.052240Z | Download | b0a9b0f6d3ac39f372c17494716acb39bf9517a789217b7f28256eb0ca011872 |
| 2.3.1 | 2024-10-29T14:44:27.000066Z | Download | 83f65107165883ba8623eb822daacb23dcf9f795c66841de758c9dd7c5a0cf28 |
| 2.4.0 | 2025-11-25T22:05:59.874420Z | Download | a2d3c4c83cac0126bf38e41eaf7bd9ed4f6635f1ee1a0cbc6f79fa9736c62cbd |
Dependencies
No direct dependencies declared.