-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
benchmark: add "byGroup" config option #26559
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
51a6b82
benchmark: add byGroup option in benchmark configs
BeniCheni a6fc43c
benchmark: adapt byGroup option with buffer-form-by-group.js benchmark
BeniCheni 272fa07
doc: add byGroup option and example in writing-and-running-benchmarks.md
BeniCheni ccce103
refactor: update const variables and comment in benchmark common.js
BeniCheni 883c90a
refactor: update let variable in benchmark buffer-from-by-group.js
BeniCheni 0bfdd66
benchmark: add process.env.NODEJS_BENCHMARK_BYPASS_GROUP support
BeniCheni 7e802ab
benchmark: correct typo of enqueueConfigs function in benchmark common
BeniCheni b961b02
benchmark: update code format in benchmark/common.js
BeniCheni 81ffaec
benchmark: rename variables in benchmark/common.js
BeniCheni 6d847e8
benchmark: rename parsedArgs variables in benchmark/common.js
BeniCheni 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 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,110 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const assert = require('assert'); | ||
const bench = common.createBenchmark(main, { | ||
groupA: { | ||
source: [ | ||
'array', | ||
'arraybuffer', | ||
'arraybuffer-middle', | ||
'buffer', | ||
'uint8array', | ||
'string', | ||
'string-utf8', | ||
'string-base64', | ||
'object', | ||
], | ||
len: [10, 2048], | ||
n: [2048] | ||
}, | ||
groupB: { | ||
source: [ | ||
'buffer', | ||
'string', | ||
], | ||
len: [2048], | ||
n: [2048] | ||
} | ||
}, { byGroup: true }); | ||
|
||
function main({ len, n, source }) { | ||
const array = new Array(len).fill(42); | ||
const arrayBuf = new ArrayBuffer(len); | ||
const str = 'a'.repeat(len); | ||
const buffer = Buffer.allocUnsafe(len); | ||
const uint8array = new Uint8Array(len); | ||
const obj = { length: null }; // Results in a new, empty Buffer | ||
|
||
let i; | ||
|
||
switch (source) { | ||
case 'array': | ||
bench.start(); | ||
for (i = 0; i < n * 1024; i++) { | ||
Buffer.from(array); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'arraybuffer': | ||
bench.start(); | ||
for (i = 0; i < n * 1024; i++) { | ||
Buffer.from(arrayBuf); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'arraybuffer-middle': | ||
const offset = ~~(len / 4); | ||
const length = ~~(len / 2); | ||
bench.start(); | ||
for (i = 0; i < n * 1024; i++) { | ||
Buffer.from(arrayBuf, offset, length); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'buffer': | ||
bench.start(); | ||
for (i = 0; i < n * 1024; i++) { | ||
Buffer.from(buffer); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'uint8array': | ||
bench.start(); | ||
for (i = 0; i < n * 1024; i++) { | ||
Buffer.from(uint8array); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'string': | ||
bench.start(); | ||
for (i = 0; i < n * 1024; i++) { | ||
Buffer.from(str); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'string-utf8': | ||
bench.start(); | ||
for (i = 0; i < n * 1024; i++) { | ||
Buffer.from(str, 'utf8'); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'string-base64': | ||
bench.start(); | ||
for (i = 0; i < n * 1024; i++) { | ||
Buffer.from(str, 'base64'); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'object': | ||
bench.start(); | ||
for (i = 0; i < n * 1024; i++) { | ||
Buffer.from(obj); | ||
} | ||
bench.end(n); | ||
break; | ||
default: | ||
assert.fail(null, null, 'Should not get here'); | ||
} | ||
} |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be simplified to