mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 15:30:56 +01:00
22b84e6216
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
104 lines
2.1 KiB
JavaScript
104 lines
2.1 KiB
JavaScript
const LEN = 1e7;
|
|
|
|
const INT8 = 0x7f;
|
|
const INT16 = 0x7fff;
|
|
const INT32 = 0x7fffffff;
|
|
const UINT8 = INT8 * 2;
|
|
const UINT16 = INT16 * 2;
|
|
const UINT32 = INT32 * 2;
|
|
|
|
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;
|
|
|
|
timer('writeUInt8', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeUInt8(i % UINT8, 0, noAssert);
|
|
}
|
|
});
|
|
|
|
timer('writeUInt16LE', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeUInt16LE(i % UINT16, 0, noAssert);
|
|
}
|
|
});
|
|
|
|
timer('writeUInt16BE', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeUInt16BE(i % UINT16, 0, noAssert);
|
|
}
|
|
});
|
|
|
|
timer('writeUInt32LE', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeUInt32LE(i % UINT32, 0, noAssert);
|
|
}
|
|
});
|
|
|
|
timer('writeUInt32BE', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeUInt32BE(i % UINT32, 0, noAssert);
|
|
}
|
|
});
|
|
|
|
timer('writeInt8', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeInt8(i % INT8, 0, noAssert);
|
|
}
|
|
});
|
|
|
|
timer('writeInt16LE', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeInt16LE(i % INT16, 0, noAssert);
|
|
}
|
|
});
|
|
|
|
timer('writeInt16BE', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeInt16BE(i % INT16, 0, noAssert);
|
|
}
|
|
});
|
|
|
|
timer('writeInt32LE', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeInt32LE(i % INT32, 0, noAssert);
|
|
}
|
|
});
|
|
|
|
timer('writeInt32BE', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeInt32BE(i % INT32, 0, noAssert);
|
|
}
|
|
});
|
|
|
|
timer('writeFloatLE', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeFloatLE(i * 0.1, 0, noAssert);
|
|
}
|
|
});
|
|
|
|
timer('writeFloatBE', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeFloatBE(i * 0.1, 0, noAssert);
|
|
}
|
|
});
|
|
|
|
timer('writeDoubleLE', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeDoubleLE(i * 0.1, 0, noAssert);
|
|
}
|
|
});
|
|
|
|
timer('writeDoubleBE', function() {
|
|
for (i = 0; i < LEN; i++) {
|
|
buff.writeDoubleBE(i * 0.1, 0, noAssert);
|
|
}
|
|
});
|