diff options
author | isaacs <i@izs.me> | 2013-02-12 10:01:50 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-02-20 02:14:33 +0400 |
commit | 3f67a48dd461e1454b81cde33f5c005de5910fa3 (patch) | |
tree | 2f22d1c3400cb1fda3628a0aa3a6096dc581717b /benchmark | |
parent | 56b22956ad3c76a747b359452fec987eab4fac5e (diff) |
bench: Add buffers/dataview_set
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/buffers/dataview_set.js | 57 | ||||
-rw-r--r-- | benchmark/dataview_set.js | 104 |
2 files changed, 57 insertions, 104 deletions
diff --git a/benchmark/buffers/dataview_set.js b/benchmark/buffers/dataview_set.js new file mode 100644 index 00000000000..ce0064edb6e --- /dev/null +++ b/benchmark/buffers/dataview_set.js @@ -0,0 +1,57 @@ + +var common = require('../common.js'); +var bench = common.createBenchmark(main, { + type: ['Uint8', 'Uint16LE', 'Uint16BE', + 'Uint32LE', 'Uint32BE', + 'Int8', 'Int16LE', 'Int16BE', + 'Int32LE', 'Int32BE', + 'Float32LE', 'Float32BE', + 'Float64LE', 'Float64BE'], + millions: [1] +}); + +const INT8 = 0x7f; +const INT16 = 0x7fff; +const INT32 = 0x7fffffff; +const UINT8 = INT8 * 2; +const UINT16 = INT16 * 2; +const UINT32 = INT32 * 2; + +var mod = { + setInt8: INT8, + setInt16: INT16, + setInt32: INT32, + setUint8: UINT8, + setUint16: UINT16, + setUint32: UINT32 +}; + +function main(conf) { + var len = +conf.millions * 1e6; + var ab = new ArrayBuffer(8); + var dv = new DataView(ab, 0, 8); + var le = /LE$/.test(conf.type); + var fn = 'set' + conf.type.replace(/[LB]E$/, ''); + + if (/int/i.test(fn)) + benchInt(dv, fn, len, le); + else + benchFloat(dv, fn, len, le); +} + +function benchInt(dv, fn, len, le) { + var m = mod[fn]; + bench.start(); + for (var i = 0; i < len; i++) { + dv[fn](0, i % m, le); + } + bench.end(len / 1e6); +} + +function benchFloat(dv, fn, len, le) { + bench.start(); + for (var i = 0; i < len; i++) { + dv[fn](0, i * 0.1, le); + } + bench.end(len / 1e6); +} diff --git a/benchmark/dataview_set.js b/benchmark/dataview_set.js deleted file mode 100644 index d0eca615153..00000000000 --- a/benchmark/dataview_set.js +++ /dev/null @@ -1,104 +0,0 @@ -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); - } -}); |