Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge package:benchmark_harness #688

Merged
merged 144 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
5dd5c5a
Initial commit
johnmccutchan Oct 31, 2012
99ba943
Keep all file names lower case.
johnmccutchan Nov 22, 2012
1e4cce0
Fix reference to BenchmarkBase.dart
johnmccutchan Nov 22, 2012
91a717a
Update version number
johnmccutchan Nov 22, 2012
81bc9e8
Have BenchmarkBase report runs, total and average run times.
johnmccutchan Dec 19, 2012
f6ae293
Update version number and add a LICENSE.txt
johnmccutchan Dec 19, 2012
e8b96b2
Update DeltaBlue and Richards benchmarks
johnmccutchan Dec 19, 2012
a2d9ba4
Add email address
johnmccutchan Dec 19, 2012
708ba40
Revert more detailed reporting change.
johnmccutchan Dec 19, 2012
29395fe
README.md update
johnmccutchan Dec 19, 2012
8583ea6
README.md tweak
johnmccutchan Dec 19, 2012
6f07315
README.md
johnmccutchan Dec 19, 2012
9669ba6
README.md
johnmccutchan Dec 19, 2012
e9cc512
README.md
johnmccutchan Dec 19, 2012
736c64f
README.md
johnmccutchan Dec 19, 2012
107a04b
README.md
johnmccutchan Dec 20, 2012
c975300
Change email address
johnmccutchan Dec 20, 2012
c7656c3
Adjusting example code to run on Dart VM version: 0.1.2.0_r17004 (Fri…
adam-singer Jan 12, 2013
41a4694
Update README.md
sethladd Feb 18, 2013
1608a67
Merge pull request dart-lang/benchmark_harness#4 from financeCoding/m…
sethladd Feb 19, 2013
ed052a0
Merge branch 'master' of https://github.com/dart-lang/benchmark_harness
johnmccutchan Apr 16, 2013
898af0e
Add RayTraceOO Dart and JS benchmark.
johnmccutchan Apr 16, 2013
5258286
Fix DeltaBlue and Richards.
johnmccutchan Apr 16, 2013
338a9b3
Renamed RayTracerOO to Tracer.
johnmccutchan Apr 17, 2013
b024456
visualize the Tracer benchmark
sethladd Apr 30, 2013
61aceef
Merge pull request dart-lang/benchmark_harness#8 from sethladd/master
johnmccutchan May 5, 2013
d18fcd4
Add FluidMotion example
johnmccutchan Jan 10, 2014
208f9eb
Benchmark harness can now emit results.
mvuksano Feb 12, 2014
383c92b
Emitter takes test name and score
mvuksano Feb 12, 2014
cc50c5a
Code refactor
mvuksano Feb 13, 2014
d329c46
Merge pull request dart-lang/benchmark_harness#15 from markovuksanovi…
johnmccutchan Feb 13, 2014
776d1ec
Bump version number and update pub package
johnmccutchan Feb 14, 2014
dc31905
Link to benchmark article
sethladd Feb 14, 2014
66a7b42
Update README.md
sethladd Feb 14, 2014
3f36848
change from the elapsedMilliseconds to elapsedMicroseconds
devoncarew Mar 2, 2014
0435560
hoist expression
devoncarew Mar 3, 2014
fae27f9
Merge pull request dart-lang/benchmark_harness#16 from dart-lang/devo…
johnmccutchan Mar 3, 2014
d8803f4
Major cleanup of JS sample code.
slightlyoff Mar 10, 2014
a27e00a
add a unit test
devoncarew Mar 12, 2014
859701c
Merge pull request dart-lang/benchmark_harness#18 from dart-lang/devo…
johnmccutchan Mar 12, 2014
ef931c0
add drone script
devoncarew Mar 12, 2014
73889ea
Merge branch 'master' into devoncarew_more_tests
devoncarew Mar 12, 2014
7336cd9
add an all.dart test suite; fix an analysis issue
devoncarew Mar 12, 2014
3bdc8fe
Clean up math methods to remove extraneous ToNumber()'s.
slightlyoff Mar 12, 2014
61f056d
Merge pull request dart-lang/benchmark_harness#19 from dart-lang/devo…
johnmccutchan Mar 13, 2014
22f7567
Merge remote-tracking branch 'upstream/master'
slightlyoff Mar 14, 2014
a8fdc4d
Remove extraneous line.
slightlyoff Mar 14, 2014
a3ece79
Merge pull request dart-lang/benchmark_harness#20 from slightlyoff/ma…
johnmccutchan Mar 14, 2014
449ae1e
Added example output and explanation for us unit.
0xcaff Mar 20, 2014
765b1fb
Added hop for analyzing and testing with ci.
0xcaff Mar 19, 2014
0e51fb0
Added version constraints to dependencies
0xcaff Mar 20, 2014
05f76a7
Merge pull request dart-lang/benchmark_harness#25 from caffinatedmonk…
kevmoo Mar 20, 2014
300168c
Merge pull request dart-lang/benchmark_harness#26 from caffinatedmonk…
johnmccutchan Mar 25, 2014
a146801
Add JavaScript sources for FluidMotion example
johnmccutchan Mar 25, 2014
024319e
Update README.md
johnmccutchan Feb 2, 2015
d893a20
Remove unused
kevmoo Apr 1, 2015
870b7ba
dependency cleanup
kevmoo Apr 1, 2015
13ab4ff
Merge pull request dart-lang/benchmark_harness#33 from dart-lang/depe…
johnmccutchan Apr 2, 2015
d16d1d7
Merge pull request dart-lang/benchmark_harness#34 from dart-lang/unused
johnmccutchan Apr 2, 2015
24ebf76
fix: migrate to modern dependencies, prepare to release 1.0.5 (dart-l…
kevmoo Jul 26, 2018
20423a1
enable and fix a number of lints
kevmoo Jan 13, 2019
10c326d
Update build_runner and build_web_compilers deps
kevmoo Jan 13, 2019
c27ef5e
fix link in readme
kevmoo Jan 13, 2019
2e71f70
update mockito dependency
kevmoo Jan 13, 2019
cb8eb4f
enable travis-ci
kevmoo Jan 13, 2019
ccae351
reference the package layout convention
jonasfj Mar 25, 2019
7912301
Merge pull request dart-lang/benchmark_harness#40 from jonasfj/refere…
jonasfj Mar 26, 2019
2e3a6eb
Enable and fix lints, test on oldest supported Dart sdk (dart-lang/be…
kevmoo May 8, 2019
b92f778
update build_web_compilers dep (dart-lang/benchmark_harness#42)
kevmoo May 21, 2019
ddb753e
fix lint
kevmoo May 28, 2019
79408f3
tidy example (dart-lang/benchmark_harness#46)
pq Nov 9, 2019
b7e342b
Fix latest pedantic lints – and a few more (dart-lang/benchmark_harne…
kevmoo Dec 26, 2019
142de6a
Update SDK dependency to 2.9.0-1
athomas Jun 23, 2020
61c6592
Opt-out examples/
athomas Jun 25, 2020
60fc47d
Enable non-nullable experiment in analysis options
athomas Jun 23, 2020
68cbb40
Update travis config to test with non-nullable enabled
athomas Jun 23, 2020
610ec2c
Add dependency overrides for dev dependencies
athomas Jun 23, 2020
a158522
Migrate result emitter test
athomas Jun 23, 2020
92419d7
Merge pull request dart-lang/benchmark_harness#49 from athomas/opt-in
athomas Jun 25, 2020
159b084
update for the 2.10 dev sdk (dart-lang/benchmark_harness#51)
jakemac53 Jul 22, 2020
a5cea1f
CI: Test on dev branch (dart-lang/benchmark_harness#52)
kevmoo Jul 23, 2020
21b2e09
minor syntax highlighting improvements
psygo Sep 10, 2020
e6ee8d5
Allow the 2.10 stable and 2.11.0 dev SDKs (dart-lang/benchmark_harnes…
natebosch Sep 29, 2020
f3f1207
prep for null safety release (dart-lang/benchmark_harness#57)
jakemac53 Nov 10, 2020
5637368
rename license file to comply with lints (dart-lang/benchmark_harness…
jakemac53 Nov 10, 2020
1479880
typos (dart-lang/benchmark_harness#59)
pq Nov 11, 2020
d63c65b
Migrate to GitHub Actions (dart-lang/benchmark_harness#60)
athomas Dec 21, 2020
a43dad9
stable null safety release (dart-lang/benchmark_harness#62)
jakemac53 Feb 5, 2021
92056e9
Remove "Learning more" link
parlough Feb 24, 2021
656b331
Update LICENSE
franklinyow Mar 31, 2021
83286a4
Merge pull request dart-lang/benchmark_harness#65 from dart-lang/fran…
franklinyow Mar 31, 2021
bb5d1fc
Update dev_dependencies on build_* (dart-lang/benchmark_harness#66)
kevmoo Apr 20, 2021
a899499
Update README example for modern Dart conventions (dart-lang/benchmar…
parlough Jun 1, 2021
49b8184
Dart format with latest SDK (dart-lang/benchmark_harness#67)
kevmoo Jul 11, 2021
a860e49
Fix updated lints (dart-lang/benchmark_harness#68)
kevmoo Aug 1, 2021
8a59b25
Change LICENSE to BSD (dart-lang/benchmark_harness#69)
mraleph Aug 18, 2021
2fee79f
Merge pull request dart-lang/benchmark_harness#63 from parlough/patch-1
whesse Sep 27, 2021
979f2b0
Merge branch 'master' into patch-1
whesse Sep 27, 2021
b618fca
Minor Syntax Highlighting Improvements
whesse Sep 27, 2021
69ad461
Move to pkg:lints (dart-lang/benchmark_harness#70)
kevmoo Oct 20, 2021
423df56
Fix analysis_options issue (dart-lang/benchmark_harness#71)
kevmoo Jan 30, 2022
d28089a
Add AsyncBenchmarkBase.
aam Aug 30, 2019
43c1085
Merge pull request dart-lang/benchmark_harness#44 from dart-lang/async
sortie Apr 29, 2022
07fd431
Version 2.1.0. (dart-lang/benchmark_harness#72)
sortie May 3, 2022
ed448fb
Update README.md
devoncarew May 3, 2022
1b7d097
Merge pull request dart-lang/benchmark_harness#74 from dart-lang/devo…
devoncarew May 3, 2022
d8f2ea8
Fix harness to not call timer repeatedly in the measured loop. (dart-…
leafpetersen Jul 6, 2022
66c7e0d
Reduce measurement overhead by allowing some degree of measurement ji…
mraleph Jul 7, 2022
684ec1b
Remove deprecated experimental invariant_booleans lint rule (dart-lan…
srawlins Jul 25, 2022
16c61c7
blast_repo fixes (dart-lang/benchmark_harness#78)
kevmoo Nov 10, 2022
2b5d9f5
Bump actions/checkout from 3.1.0 to 3.2.0 (dart-lang/benchmark_harnes…
dependabot[bot] Jan 3, 2023
33f7aba
Bump dart-lang/setup-dart from 1.3 to 1.4 (dart-lang/benchmark_harnes…
dependabot[bot] Feb 1, 2023
b7c994c
Bump actions/checkout from 3.2.0 to 3.3.0 (dart-lang/benchmark_harnes…
dependabot[bot] Feb 1, 2023
f8546d4
add a publishing workflow action to dart-lang/benchmark_harness (dart…
devoncarew Feb 2, 2023
1eb0477
Require Dart 2.19, update lints to dart_flutter_team_lints (dart-lang…
kevmoo Feb 9, 2023
3fae9ec
Spelling fixes, latest lints, move to minilibs (drop parts) (dart-lan…
kevmoo Mar 14, 2023
68c62b3
Bump dart-lang/setup-dart from 1.4.0 to 1.5.0 (dart-lang/benchmark_ha…
dependabot[bot] Apr 3, 2023
d526e07
Bump actions/checkout from 3.3.0 to 3.5.0 (dart-lang/benchmark_harnes…
dependabot[bot] Apr 3, 2023
2f0c764
Bump actions/checkout from 3.5.0 to 3.5.2 (dart-lang/benchmark_harnes…
dependabot[bot] May 8, 2023
b3d2539
Update pubspec.yaml (dart-lang/benchmark_harness#89)
devoncarew May 8, 2023
8654a17
blast_repo fixes (dart-lang/benchmark_harness#90)
devoncarew May 12, 2023
f9768e3
Bump actions/checkout from 3.5.2 to 3.5.3 (dart-lang/benchmark_harnes…
dependabot[bot] Jul 1, 2023
f80818d
Bump actions/checkout from 3.5.3 to 3.6.0 (dart-lang/benchmark_harnes…
dependabot[bot] Sep 1, 2023
f8f8297
Bump actions/checkout from 3.6.0 to 4.1.0 (dart-lang/benchmark_harnes…
dependabot[bot] Oct 1, 2023
9ecb839
Bump dart-lang/setup-dart from 1.5.0 to 1.5.1 (dart-lang/benchmark_ha…
dependabot[bot] Oct 1, 2023
03ea85a
Bump dart-lang/setup-dart from 1.5.1 to 1.6.0 (dart-lang/benchmark_ha…
dependabot[bot] Nov 1, 2023
5bb5bb6
Bump actions/checkout from 4.1.0 to 4.1.1 (dart-lang/benchmark_harnes…
dependabot[bot] Nov 1, 2023
b3a028d
Require Dart 3.2, pub dependencies, cleanup analysis_options (dart-la…
kevmoo Dec 14, 2023
77c5525
Bump dart-lang/setup-dart from 1.6.0 to 1.6.2 (dart-lang/benchmark_ha…
dependabot[bot] Feb 1, 2024
10739e7
Bump actions/checkout from 4.1.1 to 4.1.2 (dart-lang/benchmark_harnes…
dependabot[bot] Apr 1, 2024
4e05506
Add support for running perftools to use hardware performance counter…
whesse Apr 18, 2024
8220767
Version 2.3.0 (dart-lang/benchmark_harness#102)
whesse Apr 23, 2024
3050be0
Bump actions/checkout from 4.1.2 to 4.1.4 (dart-lang/benchmark_harnes…
dependabot[bot] May 1, 2024
ad71981
Bump dart-lang/setup-dart from 1.6.2 to 1.6.4 (dart-lang/benchmark_ha…
dependabot[bot] May 2, 2024
6dd1b77
blast_repo fixes (dart-lang/benchmark_harness#105)
devoncarew May 3, 2024
a9a2423
bump lints dep and fix (dart-lang/benchmark_harness#106)
kevmoo May 28, 2024
98856fb
Bump actions/checkout from 4.1.4 to 4.1.6 in the github-actions group…
dependabot[bot] Jun 1, 2024
14f47fe
blast_repo fixes (dart-lang/benchmark_harness#108)
kevmoo Jul 1, 2024
066d23e
Bump actions/checkout from 4.1.7 to 4.2.0 in the github-actions group…
dependabot[bot] Oct 1, 2024
c4527f6
Merge package:benchmark_harness into the tools monorepo
mosuem Oct 25, 2024
0d67887
Add issue template and other fixes
mosuem Oct 25, 2024
e4d0910
Moving fixes
mosuem Oct 25, 2024
9f5aab2
remove a reference to a deprecated lint
devoncarew Oct 28, 2024
ba527fc
Merge branch 'main' into merge-benchmark_harness-package
mosuem Oct 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/benchmark_harness.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: "package:benchmark_harness"
about: "Create a bug or file a feature request against package:benchmark_harness."
labels: "package:benchmark_harness"
---
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- changed-files:
- any-glob-to-any-file: 'pkgs/bazel_worker/**'

'package:benchmark_harness':
- changed-files:
- any-glob-to-any-file: 'pkgs/benchmark_harness/**'

'package:boolean_selector':
- changed-files:
- any-glob-to-any-file: 'pkgs/boolean_selector/**'
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/benchmark_harness.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: package:benchmark_harness

on:
# Run on PRs and pushes to the default branch.
push:
branches: [ main ]
paths:
- '.github/workflows/benchmark_harness.yml'
- 'pkgs/benchmark_harness/**'
pull_request:
branches: [ main ]
paths:
- '.github/workflows/benchmark_harness.yml'
- 'pkgs/benchmark_harness/**'
schedule:
- cron: "0 0 * * 0"

env:
PUB_ENVIRONMENT: bot.github

defaults:
run:
working-directory: pkgs/benchmark_harness/

jobs:
# Check code formatting and static analysis on a single OS (linux)
# against Dart dev.
analyze:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [dev]
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Analyze code
run: dart analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

# Run tests on a matrix consisting of two dimensions:
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
# 2. release channel: dev
test:
needs: analyze
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [3.2, dev]
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Run VM tests
run: dart test --platform vm
if: always() && steps.install.outcome == 'success'
- name: Run Chrome tests
run: dart test --platform chrome
if: always() && steps.install.outcome == 'success'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ don't naturally belong to other topic monorepos (like
| Package | Description | Version |
| --- | --- | --- |
| [bazel_worker](pkgs/bazel_worker/) | Protocol and utilities to implement or invoke persistent bazel workers. | [![pub package](https://img.shields.io/pub/v/bazel_worker.svg)](https://pub.dev/packages/bazel_worker) |
| [benchmark_harness](pkgs/benchmark_harness/) | The official Dart project benchmark harness. | [![pub package](https://img.shields.io/pub/v/benchmark_harness.svg)](https://pub.dev/packages/benchmark_harness) |
| [boolean_selector](pkgs/boolean_selector/) | A flexible syntax for boolean expressions, based on a simplified version of Dart's expression syntax. | [![pub package](https://img.shields.io/pub/v/boolean_selector.svg)](https://pub.dev/packages/boolean_selector) |
| [browser_launcher](pkgs/browser_launcher/) | Provides a standardized way to launch web browsers for testing and tools. | [![pub package](https://img.shields.io/pub/v/browser_launcher.svg)](https://pub.dev/packages/browser_launcher) |
| [cli_config](pkgs/cli_config/) | A library to take config values from configuration files, CLI arguments, and environment variables. | [![pub package](https://img.shields.io/pub/v/cli_config.svg)](https://pub.dev/packages/cli_config) |
Expand Down
4 changes: 4 additions & 0 deletions pkgs/benchmark_harness/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.dart_tool
.packages
.pub
pubspec.lock
50 changes: 50 additions & 0 deletions pkgs/benchmark_harness/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## 2.3.1

- Move to `dart-lang/tools` monorepo.

## 2.3.0

- Require Dart 3.2.
- Add ScoreEmitterV2 interface, documented with the intention to change
ScoreEmitter interface to match it in the next major release,
a breaking change.
- Add `PerfBenchmarkBase` class which runs the 'perf stat' command from
linux-tools on a benchmark and reports metrics from the hardware
performance counters and the iteration count, as well as the run time
measurement reported by `BenchmarkBase`.

## 2.2.2

- Added package topics to the pubspec file.
- Require Dart 2.19.

## 2.2.1

- Improve convergence speed of `BenchmarkBase` measuring algorithm by allowing
some degree of measuring jitter.

## 2.2.0

- Change measuring algorithm in `BenchmarkBase` to avoid calling stopwatch
methods repeatedly in the measuring loop. This makes measurement work better
for `run` methods 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.
26 changes: 26 additions & 0 deletions pkgs/benchmark_harness/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright 2021, the Dart project authors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
116 changes: 116 additions & 0 deletions pkgs/benchmark_harness/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
[![Build Status](https://github.com/dart-lang/tools/actions/workflows/benchmark_harness.yaml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/benchmark_harness.yaml)
[![pub package](https://img.shields.io/pub/v/benchmark_harness.svg)](https://pub.dev/packages/benchmark_harness)
[![package publisher](https://img.shields.io/pub/publisher/benchmark_harness.svg)](https://pub.dev/packages/benchmark_harness/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:

```dart
@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

* `BenchmarkBase` class that all new benchmarks should `extend`.
* `AsyncBenchmarkBase` for 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**

```yaml
dependencies:
benchmark_harness: any
```

2\. Install pub packages

```sh
dart pub install
```

3\. Add the following import:

```dart
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/`](https://dart.dev/tools/pub/package-layout#tests-and-benchmarks)
folder of your package.

```dart
// 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

```console
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.
14 changes: 14 additions & 0 deletions pkgs/benchmark_harness/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-inference: true
strict-casts: true

linter:
rules:
- avoid_unused_constructor_parameters
- cancel_subscriptions
- literal_only_boolean_expressions
- no_adjacent_strings_in_list
- unnecessary_await_in_return
36 changes: 36 additions & 0 deletions pkgs/benchmark_harness/example/template.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// 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 measures 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();
}
26 changes: 26 additions & 0 deletions pkgs/benchmark_harness/integration_test/perf_benchmark_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:benchmark_harness/perf_benchmark_harness.dart';
import 'package:test/test.dart';

class PerfBenchmark extends PerfBenchmarkBase {
PerfBenchmark(super.name);
int runCount = 0;

@override
void run() {
runCount++;
for (final i in List.filled(1000, 7)) {
runCount += i - i;
}
}
}

void main() {
test('run is called', () async {
final benchmark = PerfBenchmark('ForLoop');
await benchmark.reportPerf();
});
}
7 changes: 7 additions & 0 deletions pkgs/benchmark_harness/lib/benchmark_harness.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

export 'src/async_benchmark_base.dart';
export 'src/benchmark_base.dart' show BenchmarkBase;
export 'src/score_emitter.dart';
7 changes: 7 additions & 0 deletions pkgs/benchmark_harness/lib/perf_benchmark_harness.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

export 'src/perf_benchmark_base_stub.dart'
if (dart.library.io) 'src/perf_benchmark_base.dart';
export 'src/score_emitter.dart';
Loading
Loading