0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/buffers/buffer-base64-decode.js
Troy Connor 7021e6b52d benchmark: refactor buffer benchmarks
Add configuration object createBenchmark object for buffer size &
iteration in buffer-base64-encode & buffer-base64-decode.js.

PR-URL: https://github.com/nodejs/node/pull/10175
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
2016-12-23 11:49:52 -08:00

20 lines
490 B
JavaScript

'use strict';
const assert = require('assert');
const common = require('../common.js');
const bench = common.createBenchmark(main, {
n: [32],
});
function main(conf) {
const n = +conf.n;
const s = 'abcd'.repeat(8 << 20);
s.match(/./); // Flatten string.
assert.strictEqual(s.length % 4, 0);
const b = Buffer.allocUnsafe(s.length / 4 * 3);
b.write(s, 0, s.length, 'base64');
bench.start();
for (var i = 0; i < n; i += 1) b.base64Write(s, 0, s.length);
bench.end(n);
}