-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: refactor buffer benchmarks
Add configuration object createBenchmark object for buffer size & iteration in buffer-base64-encode & buffer-base64-decode.js. PR-URL: #10175 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Brian White <[email protected]>
- Loading branch information
1 parent
eef36e9
commit 8a562cf
Showing
2 changed files
with
18 additions
and
11 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 |
---|---|---|
@@ -1,16 +1,20 @@ | ||
'use strict'; | ||
var common = require('../common.js'); | ||
|
||
var bench = common.createBenchmark(main, {}); | ||
const bench = common.createBenchmark(main, { | ||
len: [64 * 1024 * 1024], | ||
n: [32] | ||
}); | ||
|
||
function main(conf) { | ||
var N = 64 * 1024 * 1024; | ||
var b = Buffer.allocUnsafe(N); | ||
var s = ''; | ||
var i; | ||
const n = +conf.n; | ||
const len = +conf.len; | ||
const b = Buffer.allocUnsafe(len); | ||
let s = ''; | ||
let i; | ||
for (i = 0; i < 256; ++i) s += String.fromCharCode(i); | ||
for (i = 0; i < N; i += 256) b.write(s, i, 256, 'ascii'); | ||
for (i = 0; i < len; i += 256) b.write(s, i, 256, 'ascii'); | ||
bench.start(); | ||
for (i = 0; i < 32; ++i) b.toString('base64'); | ||
bench.end(64); | ||
for (i = 0; i < n; ++i) b.toString('base64'); | ||
bench.end(n); | ||
} |