-
Notifications
You must be signed in to change notification settings - Fork 260
chore(NODE-6382): add benchmarking for helpers #717
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7ea383c
chore(NODE-6382): add benchmarking for helpers
nbbeeken adffe64
chore: move benchmarks to file
nbbeeken e49e024
chore: fix perf.send file
nbbeeken 5e1474a
chore: rename results file
nbbeeken a7ea8d0
chore: add better description for short circuiting
nbbeeken 3789acb
chore: name improvements
nbbeeken 88c6944
Merge branch 'main' into chore-custom-benchmarks
W-A-James File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" | ||
set -o xtrace | ||
|
||
npm run check:custom-bench |
This file contains hidden or 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 |
---|---|---|
|
@@ -33,3 +33,4 @@ docs/public | |
.nvmrc | ||
|
||
benchmarks.json | ||
customBenchmarkResults.json |
This file contains hidden or 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 hidden or 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,20 @@ | ||
/* eslint-disable strict */ | ||
import { BSON } from '../../../lib/bson.mjs'; | ||
|
||
const ObjectId_isValid = [ | ||
function objectid_isvalid_strlen() { | ||
BSON.ObjectId.isValid('a'); | ||
}, | ||
function objectid_isvalid_bestcase_false() { | ||
BSON.ObjectId.isValid('g6e84ebdc96f4c0772f0cbbf'); | ||
}, | ||
function objectid_isvalid_worstcase_false() { | ||
BSON.ObjectId.isValid('66e84ebdc96f4c0772f0cbbg'); | ||
}, | ||
function objectid_isvalid_true() { | ||
BSON.ObjectId.isValid('66e84ebdc96f4c0772f0cbbf'); | ||
} | ||
]; | ||
|
||
// Add benchmarks here: | ||
export const benchmarks = [...ObjectId_isValid]; |
This file contains hidden or 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,39 @@ | ||
/* eslint-disable strict */ | ||
|
||
import util from 'node:util'; | ||
import fs from 'node:fs'; | ||
import os from 'node:os'; | ||
import benchmark from 'benchmark'; | ||
import { benchmarks } from './benchmarks.mjs'; | ||
|
||
const hw = os.cpus(); | ||
const ram = os.totalmem() / 1024 ** 3; | ||
const platform = { name: hw[0].model, cores: hw.length, ram: `${ram}GB` }; | ||
|
||
const systemInfo = () => | ||
[ | ||
`\n- cpu: ${platform.name}`, | ||
`- cores: ${platform.cores}`, | ||
`- arch: ${os.arch()}`, | ||
`- os: ${process.platform} (${os.release()})`, | ||
`- ram: ${platform.ram}\n` | ||
].join('\n'); | ||
console.log(systemInfo()); | ||
|
||
const suite = new benchmark.Suite(); | ||
|
||
for (const bench of benchmarks) suite.add(bench.name, bench); | ||
|
||
suite | ||
.on('cycle', function logBenchmark(event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('complete', function outputPerfSend() { | ||
const data = Array.from(this).map(bench => ({ | ||
info: { test_name: bench.name }, | ||
metrics: [{ name: 'ops_per_sec', value: bench.hz }] | ||
})); | ||
console.log(util.inspect(data, { depth: Infinity, colors: true })); | ||
fs.writeFileSync('customBenchmarkResults.json', JSON.stringify(data), 'utf8'); | ||
}) | ||
.run(); |
This file contains hidden or 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,38 @@ | ||
# Custom Benchmark Tests | ||
|
||
In this directory are tests for code paths not covered by our spec or granular (de)serialization benchmarks. | ||
|
||
## How to write your own | ||
|
||
In `benchmarks.mjs` add a new test to an existing array or make a new array for a new subject area. | ||
Try to fit the name of the function into the format of: "subject area", "method or function" "test case that is being covered" (Ex. `objectid_isvalid_bestcase_false`). | ||
Make sure your test is added to the `benchmarks` export. | ||
|
||
### Example | ||
|
||
```js | ||
const ObjectId_isValid = [ | ||
function objectid_isvalid_strlen() { | ||
BSON.ObjectId.isValid('a'); | ||
}, | ||
// ... | ||
]; | ||
|
||
export const benchmarks = [...ObjectId_isValid]; | ||
``` | ||
|
||
## Output | ||
|
||
The JSON emitted at the end of the benchmarks must follow our performance tracking format. | ||
|
||
The JSON must be an array of "`Test`"s: | ||
|
||
```ts | ||
type Metric = { name: string, value: number } | ||
type Test = { | ||
info: { test_name: string }, | ||
metrics: Metric[] | ||
} | ||
``` | ||
|
||
The metric collected is always "ops_per_sec" so higher is better. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.