0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
nodejs/benchmark/buffer_read.js
Trevor Norris 22b84e6216 buffer: floating point read/write improvements
Improvements:
* floating point operations are approx 4x's faster
* Now write quiet NaN's
* all read/write on floating point now done in C, so no more need for
  lib/buffer_ieee754.js
* float values have more accurate min/max value checks
* add additional benchmarks for buffers read/write
* created benchmark/_bench_timer.js which is a simple library that
  can be included into any benchmark and provides an intelligent tracker
  for sync and async tests
* add benchmarks for DataView set methods
* add checks and tests to make sure offset is greater than 0
2013-01-16 10:17:20 -08:00

98 lines
1.8 KiB
JavaScript

const LEN = 1e7;
const noAssert = process.argv[3] == 'true' ? true
: process.argv[3] == 'false' ? false
: undefined;
var timer = require('./_bench_timer');
var buff = (process.argv[2] == 'slow') ?
(new require('buffer').SlowBuffer(8)) :
(new Buffer(8));
var i;
buff.writeDoubleLE(0, 0, noAssert);
timer('readUInt8', function() {
for (i = 0; i < LEN; i++) {
buff.readUInt8(0, noAssert);
}
});
timer('readUInt16LE', function() {
for (i = 0; i < LEN; i++) {
buff.readUInt16LE(0, noAssert);
}
});
timer('readUInt16BE', function() {
for (i = 0; i < LEN; i++) {
buff.readUInt16BE(0, noAssert);
}
});
timer('readUInt32LE', function() {
for (i = 0; i < LEN; i++) {
buff.readUInt32LE(0, noAssert);
}
});
timer('readUInt32BE', function() {
for (i = 0; i < LEN; i++) {
buff.readUInt32BE(0, noAssert);
}
});
timer('readInt8', function() {
for (i = 0; i < LEN; i++) {
buff.readInt8(0, noAssert);
}
});
timer('readInt16LE', function() {
for (i = 0; i < LEN; i++) {
buff.readInt16LE(0, noAssert);
}
});
timer('readInt16BE', function() {
for (i = 0; i < LEN; i++) {
buff.readInt16BE(0, noAssert);
}
});
timer('readInt32LE', function() {
for (i = 0; i < LEN; i++) {
buff.readInt32LE(0, noAssert);
}
});
timer('readInt32BE', function() {
for (i = 0; i < LEN; i++) {
buff.readInt32BE(0, noAssert);
}
});
timer('readFloatLE', function() {
for (i = 0; i < LEN; i++) {
buff.readFloatLE(0, noAssert);
}
});
timer('readFloatBE', function() {
for (i = 0; i < LEN; i++) {
buff.readFloatBE(0, noAssert);
}
});
timer('readDoubleLE', function() {
for (i = 0; i < LEN; i++) {
buff.readDoubleLE(0, noAssert);
}
});
timer('readDoubleBE', function() {
for (i = 0; i < LEN; i++) {
buff.readDoubleBE(0, noAssert);
}
});