-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(benchmark): add benchmark executor script
- Loading branch information
Showing
49 changed files
with
489 additions
and
570 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import child from 'node:child_process'; | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import url from 'node:url'; | ||
|
||
const _dirname = path.dirname(url.fileURLToPath(import.meta.url)); | ||
const packageDirectory = path.resolve(_dirname, '..'); | ||
|
||
const distDirectory = path.join(packageDirectory, 'dist'); | ||
const srcDirectory = path.join(packageDirectory, 'src'); | ||
|
||
const benchTaskFolders = ['factories', 'methods']; | ||
|
||
const taskPaths = benchTaskFolders | ||
.map((folder) => | ||
fs | ||
.readdirSync(path.join(distDirectory, folder), { withFileTypes: true }) | ||
.filter((dirent) => dirent.isFile()) | ||
.map((dirent) => path.join(folder, dirent.name)), | ||
) | ||
.flat(); | ||
|
||
console.log(`Found ${taskPaths.length} bench tasks`); | ||
for (const taskPath of taskPaths) { | ||
console.log(`- ${taskPath}`); | ||
} | ||
|
||
for (const taskPath of taskPaths) { | ||
const jsFilePath = path.join(distDirectory, taskPath); | ||
const logFileName = path.format({ | ||
...path.parse(taskPath), | ||
base: undefined, | ||
ext: '.log', | ||
}); | ||
const logFilePath = path.join(srcDirectory, logFileName); | ||
|
||
console.log(`node ${jsFilePath} > ${logFilePath}`); | ||
child.execSync(`node ${jsFilePath} > ${logFilePath}`); | ||
} |
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,33 @@ | ||
> rustresult Err: | ||
RustlikeResult { | ||
_type: 'err', | ||
_value: undefined, | ||
_error: 'error message' | ||
} | ||
|
||
> neverthrow err: | ||
Err { error: 'error message' } | ||
|
||
> effect Effect.fail: | ||
{ | ||
_id: 'Exit', | ||
_tag: 'Failure', | ||
cause: { _id: 'Cause', _tag: 'Fail', failure: 'error message' } | ||
} | ||
|
||
> effect Exit.fail: | ||
{ | ||
_id: 'Exit', | ||
_tag: 'Failure', | ||
cause: { _id: 'Cause', _tag: 'Fail', failure: 'error message' } | ||
} | ||
|
||
Loop N: 100,000 | ||
┌─────────┬──────────────────────┬──────────────────────┬──────────────┬────────────────┬───────────────┬─────────┐ | ||
│ (index) │ task │ mean (ns) │ median (ns) │ mean (op/s) │ median (op/s) │ samples │ | ||
├─────────┼──────────────────────┼──────────────────────┼──────────────┼────────────────┼───────────────┼─────────┤ | ||
│ 0 │ 'rustresult Err' │ '396911.70 ± 0.56%' │ '373600.01' │ '2566 ± 0.50%' │ '2677' │ 2520 │ | ||
│ 1 │ 'neverthrow err' │ '272838.43 ± 0.53%' │ '252300.02' │ '3751 ± 0.46%' │ '3964' │ 3666 │ | ||
│ 2 │ 'effect Effect.fail' │ '1199478.54 ± 0.99%' │ '1157300.00' │ '845 ± 0.68%' │ '864' │ 834 │ | ||
│ 3 │ 'effect Exit.fail' │ '1149108.72 ± 0.57%' │ '1125799.89' │ '876 ± 0.52%' │ '888' │ 871 │ | ||
└─────────┴──────────────────────┴──────────────────────┴──────────────┴────────────────┴───────────────┴─────────┘ |
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,21 @@ | ||
> rustresult Ok: | ||
RustlikeResult { _type: 'ok', _value: 1, _error: undefined } | ||
|
||
> neverthrow ok: | ||
Ok { value: 1 } | ||
|
||
> effect Effect.succeed: | ||
{ _id: 'Exit', _tag: 'Success', value: 1 } | ||
|
||
> effect Exit.succeed: | ||
{ _id: 'Exit', _tag: 'Success', value: 1 } | ||
|
||
Loop N: 100,000 | ||
┌─────────┬─────────────────────────┬─────────────────────┬─────────────┬────────────────┬───────────────┬─────────┐ | ||
│ (index) │ task │ mean (ns) │ median (ns) │ mean (op/s) │ median (op/s) │ samples │ | ||
├─────────┼─────────────────────────┼─────────────────────┼─────────────┼────────────────┼───────────────┼─────────┤ | ||
│ 0 │ 'rustresult Ok' │ '405076.67 ± 0.54%' │ '381500.01' │ '2511 ± 0.49%' │ '2621' │ 2469 │ | ||
│ 1 │ 'neverthrow ok' │ '273384.09 ± 0.56%' │ '253700.02' │ '3752 ± 0.48%' │ '3942' │ 3658 │ | ||
│ 2 │ 'effect Effect.succeed' │ '698827.05 ± 0.52%' │ '700500.01' │ '1445 ± 0.49%' │ '1428' │ 1431 │ | ||
│ 3 │ 'effect Exit.succeed' │ '694094.11 ± 0.52%' │ '696500.06' │ '1454 ± 0.49%' │ '1436' │ 1441 │ | ||
└─────────┴─────────────────────────┴─────────────────────┴─────────────┴────────────────┴───────────────┴─────────┘ |
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,20 @@ | ||
> rustresult Result.and: | ||
[ | ||
RustlikeResult { _type: 'ok', _value: 100, _error: undefined }, | ||
RustlikeResult { | ||
_type: 'err', | ||
_value: undefined, | ||
_error: 'error message' | ||
} | ||
] | ||
|
||
> neverthrow Result.and sim: | ||
[ Ok { value: 100 }, Err { error: 'error message' } ] | ||
|
||
Loop N: 100,000 | ||
┌─────────┬─────────────────────────────┬─────────────────────┬─────────────┬────────────────┬───────────────┬─────────┐ | ||
│ (index) │ task │ mean (ns) │ median (ns) │ mean (op/s) │ median (op/s) │ samples │ | ||
├─────────┼─────────────────────────────┼─────────────────────┼─────────────┼────────────────┼───────────────┼─────────┤ | ||
│ 0 │ 'rustresult Result.and' │ '291635.03 ± 0.36%' │ '277100.09' │ '3459 ± 0.29%' │ '3609' │ 3429 │ | ||
│ 1 │ 'neverthrow Result.and sim' │ '194534.53 ± 0.30%' │ '202000.14' │ '5209 ± 0.33%' │ '4950' │ 5141 │ | ||
└─────────┴─────────────────────────────┴─────────────────────┴─────────────┴────────────────┴───────────────┴─────────┘ |
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,20 @@ | ||
> rustresult Result.andThen: | ||
[ | ||
RustlikeResult { _type: 'ok', _value: 2, _error: undefined }, | ||
RustlikeResult { | ||
_type: 'err', | ||
_value: undefined, | ||
_error: 'error message' | ||
} | ||
] | ||
|
||
> neverthrow Result.andThen: | ||
[ Ok { value: 2 }, Err { error: 'error message' } ] | ||
|
||
Loop N: 100,000 | ||
┌─────────┬─────────────────────────────┬─────────────────────┬─────────────────────┬────────────────┬───────────────┬─────────┐ | ||
│ (index) │ task │ mean (ns) │ median (ns) │ mean (op/s) │ median (op/s) │ samples │ | ||
├─────────┼─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼───────────────┼─────────┤ | ||
│ 0 │ 'rustresult Result.andThen' │ '688856.68 ± 0.14%' │ '682300.09' │ '1453 ± 0.12%' │ '1466' │ 1452 │ | ||
│ 1 │ 'neverthrow Result.andThen' │ '460866.04 ± 0.34%' │ '446949.96 ± 49.83' │ '2180 ± 0.27%' │ '2237' │ 2170 │ | ||
└─────────┴─────────────────────────────┴─────────────────────┴─────────────────────┴────────────────┴───────────────┴─────────┘ |
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,17 @@ | ||
> rustresult Result.err: | ||
[ undefined, 'error message' ] | ||
|
||
> neverthrow Result.err sim: | ||
[ undefined, 'error message' ] | ||
|
||
> effect Exit.err sim: | ||
[ undefined, 'error message' ] | ||
|
||
Loop N: 100,000 | ||
┌─────────┬─────────────────────────────┬──────────────────────┬───────────────────────┬─────────────────┬───────────────┬─────────┐ | ||
│ (index) │ task │ mean (ns) │ median (ns) │ mean (op/s) │ median (op/s) │ samples │ | ||
├─────────┼─────────────────────────────┼──────────────────────┼───────────────────────┼─────────────────┼───────────────┼─────────┤ | ||
│ 0 │ 'rustresult Result.err' │ '24746.12 ± 0.09%' │ '24499.89' │ '40601 ± 0.05%' │ '40817' │ 40411 │ | ||
│ 1 │ 'neverthrow Result.err sim' │ '73818.62 ± 0.04%' │ '73799.85' │ '13552 ± 0.03%' │ '13550' │ 13547 │ | ||
│ 2 │ 'effect Exit.err sim' │ '1941183.71 ± 0.67%' │ '1904399.99 ± 100.02' │ '518 ± 0.61%' │ '525' │ 516 │ | ||
└─────────┴─────────────────────────────┴──────────────────────┴───────────────────────┴─────────────────┴───────────────┴─────────┘ |
Oops, something went wrong.