2016-07-07 04:57:39 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common.js');
|
2023-10-25 20:46:33 +00:00
|
|
|
const assert = require('assert');
|
2016-07-07 04:57:39 +00:00
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
2019-03-04 00:34:00 +00:00
|
|
|
len: [64, 1024],
|
2023-02-04 18:19:25 +00:00
|
|
|
n: [1e6],
|
2016-07-07 04:57:39 +00:00
|
|
|
});
|
|
|
|
|
2017-12-30 02:59:57 +00:00
|
|
|
function main({ len, n }) {
|
2016-07-07 04:57:39 +00:00
|
|
|
const buf = Buffer.alloc(len);
|
|
|
|
|
2019-12-13 17:43:41 +00:00
|
|
|
for (let i = 0; i < buf.length; i++)
|
2016-07-07 04:57:39 +00:00
|
|
|
buf[i] = i & 0xff;
|
|
|
|
|
2023-10-25 20:46:33 +00:00
|
|
|
const plain = buf;
|
2016-07-07 04:57:39 +00:00
|
|
|
|
|
|
|
bench.start();
|
|
|
|
|
2023-10-25 20:46:33 +00:00
|
|
|
let tmp;
|
|
|
|
|
2019-12-13 17:43:41 +00:00
|
|
|
for (let i = 0; i < n; i += 1)
|
2023-10-25 20:46:33 +00:00
|
|
|
tmp = plain.toString('hex');
|
2016-07-07 04:57:39 +00:00
|
|
|
|
|
|
|
bench.end(n);
|
2023-10-25 20:46:33 +00:00
|
|
|
|
|
|
|
assert.strictEqual(typeof tmp, 'string');
|
2016-07-07 04:57:39 +00:00
|
|
|
}
|