0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 15:30:56 +01:00
nodejs/benchmark/dataview_set.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

105 lines
2.0 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 dv = new DataView(buff);
var i;
timer('setUint8', function() {
for (i = 0; i < LEN; i++) {
dv.setUint8(0, i % UINT8);
}
});
timer('setUint16 - LE', function() {
for (i = 0; i < LEN; i++) {
dv.setUint16(0, i % UINT16, true);
}
});
timer('setUint16 - BE', function() {
for (i = 0; i < LEN; i++) {
dv.setUint16(0, i % UINT16);
}
});
timer('setUint32 - LE', function() {
for (i = 0; i < LEN; i++) {
dv.setUint32(0, i % UINT32, true);
}
});
timer('setUint32 - BE', function() {
for (i = 0; i < LEN; i++) {
dv.setUint32(0, i % UINT32);
}
});
timer('setInt8', function() {
for (i = 0; i < LEN; i++) {
dv.setInt8(0, i % INT8);
}
});
timer('setInt16 - LE', function() {
for (i = 0; i < LEN; i++) {
dv.setInt16(0, i % INT16, true);
}
});
timer('setInt16 - BE', function() {
for (i = 0; i < LEN; i++) {
dv.setInt16(0, i % INT16);
}
});
timer('setInt32 - LE', function() {
for (i = 0; i < LEN; i++) {
dv.setInt32(0, i % INT32, true);
}
});
timer('setInt32 - BE', function() {
for (i = 0; i < LEN; i++) {
dv.setInt32(0, i % INT32);
}
});
timer('setFloat32 - LE', function() {
for (i = 0; i < LEN; i++) {
dv.setFloat32(0, i * 0.1, true);
}
});
timer('setFloat32 - BE', function() {
for (i = 0; i < LEN; i++) {
dv.setFloat32(0, i * 0.1);
}
});
timer('setFloat64 - LE', function() {
for (i = 0; i < LEN; i++) {
dv.setFloat64(0, i * 0.1, true);
}
});
timer('setFloat64 - BE', function() {
for (i = 0; i < LEN; i++) {
dv.setFloat64(0, i * 0.1);
}
});