2018-01-02 12:00:59 +08:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
|
|
|
|
|
|
const types = [
|
|
|
|
'IntBE',
|
2018-01-03 08:10:57 +08:00
|
|
|
'IntLE',
|
|
|
|
'UIntBE',
|
|
|
|
'UIntLE'
|
2018-01-02 12:00:59 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
|
|
noAssert: ['false', 'true'],
|
|
|
|
buffer: ['fast', 'slow'],
|
|
|
|
type: types,
|
|
|
|
millions: [1],
|
|
|
|
byteLength: [1, 2, 4, 6]
|
|
|
|
});
|
|
|
|
|
2018-01-23 20:17:39 +08:00
|
|
|
function main({ millions, noAssert, buf, type, byteLength }) {
|
|
|
|
noAssert = noAssert === 'true';
|
|
|
|
type = type || 'UInt8';
|
|
|
|
const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
|
2018-01-02 12:00:59 +08:00
|
|
|
const buff = new clazz(8);
|
|
|
|
const fn = `read${type}`;
|
|
|
|
|
|
|
|
buff.writeDoubleLE(0, 0, noAssert);
|
|
|
|
bench.start();
|
2018-01-23 20:17:39 +08:00
|
|
|
for (var i = 0; i !== millions * 1e6; i++) {
|
|
|
|
buff[fn](0, byteLength, noAssert);
|
|
|
|
}
|
|
|
|
bench.end(millions);
|
2018-01-02 12:00:59 +08:00
|
|
|
}
|