-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
130 additions
and
0 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,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 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 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,22 @@ | ||
/* eslint-disable strict */ | ||
import { BSON } from '../../../lib/bson.mjs'; | ||
|
||
const ObjectId_isValid = [ | ||
function objectid_isvalid_wrong_string_length() { | ||
BSON.ObjectId.isValid('a'); | ||
}, | ||
/** wrong character at the start, could be the most short circuited code path */ | ||
function objectid_isvalid_invalid_hex_at_start() { | ||
BSON.ObjectId.isValid('g6e84ebdc96f4c0772f0cbbf'); | ||
}, | ||
/** wrong character at the end, could be the least short circuited code path */ | ||
function objectid_isvalid_invalid_hex_at_end() { | ||
BSON.ObjectId.isValid('66e84ebdc96f4c0772f0cbbg'); | ||
}, | ||
function objectid_isvalid_valid_hex_string() { | ||
BSON.ObjectId.isValid('66e84ebdc96f4c0772f0cbbf'); | ||
} | ||
]; | ||
|
||
// Add benchmarks here: | ||
export const benchmarks = [...ObjectId_isValid]; |
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,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 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. |