-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added performance benchmarking doc (#4169)
Co-authored-by: Tyler Benson <[email protected]> Co-authored-by: Marc Pichler <[email protected]>
- Loading branch information
1 parent
5af8653
commit 5ce32c0
Showing
4 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 merge to main, and the results are available at <https://open-telemetry.github.io/opentelemetry-js/benchmark>. | ||
|
||
## 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 merge to main (to track trend over time), register the new test file by requiring it in `test/performance/benchmark/index.js`. | ||
|
||
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" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters