-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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 <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
- Loading branch information
1 parent
59aa4e9
commit 75d6f11
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); | ||
} |