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

Added performance benchmarking doc #4169

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :books: (Refine Doc)

* docs(contributing): added guidelines for adding benchmark tests [#4169](https://github.com/open-telemetry/opentelemetry-js/pull/4169)

### :house: (Internal)

* test: added a performance benchmark test for span creation [#4105](https://github.com/open-telemetry/opentelemetry-js/pull/4105)
Expand Down
53 changes: 53 additions & 0 deletions doc/contributing/benchmark-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

# Performance Benchmark Testing Guide

Benchmark tests are intended to measure performance of small units of code.

It is recommended that operations that have a high impact on the performance of the SDK (or potential for) are accompanied by a benchmark test. This helps end-users understand the performance trend over time, and it also helps maintainers catch performance regressions.

Benchmark tests are run automatically with every release, and the results are available at <https://open-telemetry.github.io/opentelemetry-js/benchmark>.
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved

## Running benchmark tests

Performance benchmark tests can be run from the root for all modules or from a single module directory only for that module:

``` bash
# benchmark all modules
npm run test:bench

# benchmark a single module
cd packages/opentelemetry-sdk-trace-base
npm run test:bench
```

## Adding a benchmark test

Unlike unit tests, benchmark tests should be written in plain JavaScript (not Typescript).

Add a new test file in folder `test/performance/benchmark` using the following as a template:

``` javascript
const Benchmark = require('benchmark');

const suite = new Benchmark.Suite();

suite.on('cycle', event => {
console.log(String(event.target));
});

suite.add('new benchmark test', function() {
// write code to test ...
});

suite.run();
```

## Automatically running benchmark tests

If you want your test to run automatically with every release (to track trend over time), register the new test file by requiring it in `test/performance/benchmark/index.js`.
martinkuba marked this conversation as resolved.
Show resolved Hide resolved

Add the `test:bench` script in package.json, if the module does not contain it already.

``` json
"test:bench": "node test/performance/benchmark/index.js | tee .benchmark-results.txt"
```