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',
|
2019-02-05 14:06:08 +08:00
|
|
|
'UIntLE',
|
2018-01-02 12:00:59 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
|
|
buffer: ['fast', 'slow'],
|
|
|
|
type: types,
|
2018-03-17 23:19:09 +08:00
|
|
|
n: [1e6],
|
2018-01-31 04:06:59 +08:00
|
|
|
byteLength: [1, 2, 3, 4, 5, 6]
|
2018-01-02 12:00:59 +08:00
|
|
|
});
|
|
|
|
|
2018-03-17 23:19:09 +08:00
|
|
|
function main({ n, buf, type, byteLength }) {
|
2018-01-23 20:17:39 +08:00
|
|
|
const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
|
2018-01-02 12:00:59 +08:00
|
|
|
const buff = new clazz(8);
|
2018-01-31 04:06:59 +08:00
|
|
|
const fn = `read${type || 'IntBE'}`;
|
2018-01-02 12:00:59 +08:00
|
|
|
|
2018-01-31 04:06:59 +08:00
|
|
|
buff.writeDoubleLE(0, 0);
|
2018-01-02 12:00:59 +08:00
|
|
|
bench.start();
|
2018-03-17 23:19:09 +08:00
|
|
|
for (var i = 0; i !== n; i++) {
|
2018-01-31 04:06:59 +08:00
|
|
|
buff[fn](0, byteLength);
|
2018-01-23 20:17:39 +08:00
|
|
|
}
|
2018-03-17 23:19:09 +08:00
|
|
|
bench.end(n);
|
2018-01-02 12:00:59 +08:00
|
|
|
}
|