From: Feross Aboukhadijeh Date: Sun, 26 Oct 2014 23:05:46 +0000 (-0700) Subject: improve perf tests X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=71d3dfa8af4f511083d2e23b8349d7491f6c792d;p=buffer.git improve perf tests more consistent, added uint8array as comparison to all tests --- diff --git a/perf/bracket-notation.js b/perf/bracket-notation.js deleted file mode 100644 index 8461567..0000000 --- a/perf/bracket-notation.js +++ /dev/null @@ -1,37 +0,0 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() - -global.NewBuffer = require('../').Buffer // native-buffer-browserify -global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify - -var LENGTH = 50 - -var newTarget = NewBuffer(LENGTH) -var oldTarget = OldBuffer(LENGTH) -var nodeTarget = Buffer(LENGTH) - -suite.add('NewBuffer#bracket-notation', function () { - for (var i = 0; i < LENGTH; i++) { - newTarget[i] = i + 97 - } -}) -.add('OldBuffer#bracket-notation', function () { - for (var i = 0; i < LENGTH; i++) { - oldTarget[i] = i + 97 - } -}) -.add('Buffer#bracket-notation', function () { - for (var i = 0; i < LENGTH; i++) { - nodeTarget[i] = i + 97 - } -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) -.on('complete', function () { - console.log('Fastest is ' + this.filter('fastest').pluck('name')) -}) -.run({ 'async': true }) diff --git a/perf/comparison/bracket-notation.js b/perf/comparison/bracket-notation.js index afd69eb..517efa4 100644 --- a/perf/comparison/bracket-notation.js +++ b/perf/comparison/bracket-notation.js @@ -1,37 +1,27 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() - -global.NewBuffer = require('../../').Buffer // native-buffer-browserify -global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify +var BrowserBuffer = require('../../').Buffer // (this module) +var util = require('./util') +var suite = util.suite() var LENGTH = 50 +var browserBuffer = new BrowserBuffer(LENGTH) +var typedarray = new Uint8Array(LENGTH) +var nodeBuffer = new Buffer(LENGTH) -var newTarget = NewBuffer(LENGTH) -var oldTarget = OldBuffer(LENGTH) -var nodeTarget = Buffer(LENGTH) +suite + .add('BrowserBuffer#bracket-notation', function () { + for (var i = 0; i < LENGTH; i++) { + browserBuffer[i] = i + 97 + } + }) + .add('Uint8Array#bracket-notation', function () { + for (var i = 0; i < LENGTH; i++) { + typedarray[i] = i + 97 + } + }) -suite.add('NewBuffer#bracket-notation', function () { - for (var i = 0; i < LENGTH; i++) { - newTarget[i] = i + 97 - } -}) -.add('OldBuffer#bracket-notation', function () { - for (var i = 0; i < LENGTH; i++) { - oldTarget[i] = i + 97 - } -}) -.add('Buffer#bracket-notation', function () { - for (var i = 0; i < LENGTH; i++) { - nodeTarget[i] = i + 97 - } -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) -.on('complete', function () { - console.log('Fastest is ' + this.filter('fastest').pluck('name')) -}) -.run({ 'async': true }) +if (!process.browser) suite + .add('NodeBuffer#bracket-notation', function () { + for (var i = 0; i < LENGTH; i++) { + nodeBuffer[i] = i + 97 + } + }) diff --git a/perf/comparison/concat.js b/perf/comparison/concat.js index c8fb193..55ba924 100644 --- a/perf/comparison/concat.js +++ b/perf/comparison/concat.js @@ -1,40 +1,32 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() +var BrowserBuffer = require('../../').Buffer // (this module) +var util = require('./util') +var suite = util.suite() -global.NewBuffer = require('../../').Buffer // native-buffer-browserify -global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify +var LENGTH = 160 +var browserBuffer = new BrowserBuffer(LENGTH) +var browserBuffer2 = new BrowserBuffer(LENGTH) +var typedarray = new Uint8Array(LENGTH) +var typedarray2 = new Uint8Array(LENGTH) +var nodeBuffer = new Buffer(LENGTH) +var nodeBuffer2 = new Buffer(LENGTH) -var LENGTH = 16 - -var newBuf = NewBuffer(LENGTH) -var newBuf2 = NewBuffer(LENGTH) -var oldBuf = OldBuffer(LENGTH) -var oldBuf2 = OldBuffer(LENGTH) -var nodeBuf = Buffer(LENGTH) -var nodeBuf2 = Buffer(LENGTH) - -;[newBuf, newBuf2, oldBuf, oldBuf2, nodeBuf, nodeBuf2].forEach(function (buf) { +;[browserBuffer, browserBuffer2, typedarray, typedarray2, nodeBuffer, nodeBuffer2].forEach(function (buf) { for (var i = 0; i < LENGTH; i++) { - buf[i] = 42 + buf[i] = i + 97 } }) -suite.add('NewBuffer#concat', function () { - var x = Buffer.concat([newBuf, newBuf2]) -}) -.add('OldBuffer#concat', function () { - var x = Buffer.concat([oldBuf, oldBuf2]) -}) -.add('Buffer#concat', function () { - var x = Buffer.concat([nodeBuf, nodeBuf2]) -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) -.on('complete', function () { - console.log('Fastest is ' + this.filter('fastest').pluck('name')) -}) -.run({ 'async': true }) \ No newline at end of file +suite + .add('BrowserBuffer#concat', function () { + var x = BrowserBuffer.concat([browserBuffer, browserBuffer2], LENGTH * 2) + }) + .add('Uint8Array#concat', function () { + var x = new Uint8Array(LENGTH * 2) + x.set(typedarray, 0) + x.set(typedarray2, typedarray.length) + }) + +if (!process.browser) suite + .add('NodeBuffer#concat', function () { + var x = Buffer.concat([nodeBuffer, nodeBuffer2], LENGTH * 2) + }) diff --git a/perf/comparison/copy-big.js b/perf/comparison/copy-big.js index 8d355d8..2ad97a0 100644 --- a/perf/comparison/copy-big.js +++ b/perf/comparison/copy-big.js @@ -1,35 +1,26 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() +var BrowserBuffer = require('../../').Buffer // (this module) +var util = require('./util') +var suite = util.suite() -global.NewBuffer = require('../../').Buffer // native-buffer-browserify -global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify +var LENGTH = 16000 -var LENGTH = 10000 +var browserSubject = new BrowserBuffer(LENGTH) +var typedarraySubject = new Uint8Array(LENGTH) +var nodeSubject = new Buffer(LENGTH) -var newSubject = NewBuffer(LENGTH) -var oldSubject = OldBuffer(LENGTH) -var nodeSubject = Buffer(LENGTH) +var browserTarget = new BrowserBuffer(LENGTH) +var typedarrayTarget = new Uint8Array(LENGTH) +var nodeTarget = new Buffer(LENGTH) -var newTarget = NewBuffer(LENGTH) -var oldTarget = OldBuffer(LENGTH) -var nodeTarget = Buffer(LENGTH) +suite + .add('BrowserBuffer#copy (' + LENGTH + ')', function () { + browserSubject.copy(browserTarget) + }) + .add('Uint8Array#copy (' + LENGTH + ')', function () { + typedarrayTarget.set(typedarraySubject, 0) + }) -suite.add('NewBuffer#copy', function () { - newSubject.copy(newTarget) -}) -.add('OldBuffer#copy', function () { - oldSubject.copy(oldTarget) -}) -.add('Buffer#copy', function () { - nodeSubject.copy(nodeTarget) -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) -.on('complete', function () { - console.log('Fastest is ' + this.filter('fastest').pluck('name')) -}) -.run({ 'async': true }) \ No newline at end of file +if (!process.browser) suite + .add('NodeBuffer#copy (' + LENGTH + ')', function () { + nodeSubject.copy(nodeTarget) + }) diff --git a/perf/comparison/copy.js b/perf/comparison/copy.js index 0f2b0df..f79f0d9 100644 --- a/perf/comparison/copy.js +++ b/perf/comparison/copy.js @@ -1,35 +1,26 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() +var BrowserBuffer = require('../../').Buffer // (this module) +var util = require('./util') +var suite = util.suite() -global.NewBuffer = require('../../').Buffer // native-buffer-browserify -global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify +var LENGTH = 16 -var LENGTH = 10 +var browserSubject = new BrowserBuffer(LENGTH) +var typedarraySubject = new Uint8Array(LENGTH) +var nodeSubject = new Buffer(LENGTH) -var newSubject = NewBuffer(LENGTH) -var oldSubject = OldBuffer(LENGTH) -var nodeSubject = Buffer(LENGTH) +var browserTarget = new BrowserBuffer(LENGTH) +var typedarrayTarget = new Uint8Array(LENGTH) +var nodeTarget = new Buffer(LENGTH) -var newTarget = NewBuffer(LENGTH) -var oldTarget = OldBuffer(LENGTH) -var nodeTarget = Buffer(LENGTH) +suite + .add('BrowserBuffer#copy (' + LENGTH + ')', function () { + browserSubject.copy(browserTarget) + }) + .add('Uint8Array#copy (' + LENGTH + ')', function () { + typedarrayTarget.set(typedarraySubject, 0) + }) -suite.add('NewBuffer#copy', function () { - newSubject.copy(newTarget) -}) -.add('OldBuffer#copy', function () { - oldSubject.copy(oldTarget) -}) -.add('Buffer#copy', function () { - nodeSubject.copy(nodeTarget) -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) -.on('complete', function () { - console.log('Fastest is ' + this.filter('fastest').pluck('name')) -}) -.run({ 'async': true }) \ No newline at end of file +if (!process.browser) suite + .add('NodeBuffer#copy (' + LENGTH + ')', function () { + nodeSubject.copy(nodeTarget) + }) diff --git a/perf/comparison/index.html b/perf/comparison/index.html deleted file mode 100644 index ebd6fcf..0000000 --- a/perf/comparison/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/perf/comparison/new-big.js b/perf/comparison/new-big.js new file mode 100644 index 0000000..81e6735 --- /dev/null +++ b/perf/comparison/new-big.js @@ -0,0 +1,18 @@ +var BrowserBuffer = require('../../').Buffer // (this module) +var util = require('./util') +var suite = util.suite() + +var LENGTH = 16000 + +suite + .add('BrowserBuffer#new (' + LENGTH + ')', function () { + var buf = new BrowserBuffer(LENGTH) + }) + .add('Uint8Array#new (' + LENGTH + ')', function () { + var buf = new Uint8Array(LENGTH) + }) + +if (!process.browser) suite + .add('NodeBuffer#new (' + LENGTH + ')', function () { + var buf = new Buffer(LENGTH) + }) diff --git a/perf/comparison/new.js b/perf/comparison/new.js index 7751533..4027a0a 100644 --- a/perf/comparison/new.js +++ b/perf/comparison/new.js @@ -1,30 +1,16 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() +var BrowserBuffer = require('../../').Buffer // (this module) +var util = require('./util') +var suite = util.suite() -global.NewBuffer = require('../../').Buffer // native-buffer-browserify -global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify +var LENGTH = 16 -var LENGTH = 10 - -suite.add('NewBuffer#new', function () { - var buf = NewBuffer(LENGTH) -}) -.add('Uint8Array#new', function () { - var buf = new Uint8Array(LENGTH) -}) -.add('OldBuffer#new', function () { - var buf = OldBuffer(LENGTH) -}) -.add('Buffer#new', function () { - var buf = Buffer(LENGTH) -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) -.on('complete', function () { - console.log('Fastest is ' + this.filter('fastest').pluck('name')) -}) -.run({ 'async': true }) \ No newline at end of file +suite + .add('BrowserBuffer#new (' + LENGTH + ')', function () { + var buf = new BrowserBuffer(LENGTH) + }) + .add('Uint8Array#new (' + LENGTH + ')', function () { + var buf = new Uint8Array(LENGTH) + }) + .add('NodeBuffer#new (' + LENGTH + ')', function () { + var buf = new Buffer(LENGTH) + }) diff --git a/perf/comparison/readDoubleBE.js b/perf/comparison/readDoubleBE.js index 828bc37..4c14f9a 100644 --- a/perf/comparison/readDoubleBE.js +++ b/perf/comparison/readDoubleBE.js @@ -1,43 +1,39 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() +var BrowserBuffer = require('../../').Buffer // (this module) +var util = require('./util') +var suite = util.suite() -global.NewBuffer = require('../../').Buffer // native-buffer-browserify -global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify +var LENGTH = 160 -var LENGTH = 10 +var browserBuffer = new BrowserBuffer(LENGTH * 8) +var typedarray = new Uint8Array(LENGTH * 8) +var dataview = new DataView(typedarray.buffer) +var nodeBuffer = new Buffer(LENGTH * 8) -var newTarget = NewBuffer(LENGTH * 8) -var oldTarget = OldBuffer(LENGTH * 8) -var nodeTarget = Buffer(LENGTH * 8) - -;[newTarget, oldTarget, nodeTarget].forEach(function (buf) { +;[browserBuffer, nodeBuffer].forEach(function (buf) { for (var i = 0; i < LENGTH; i++) { buf.writeDoubleBE(97.1919 + i, i * 8) } }) -suite.add('NewBuffer#readDoubleBE', function () { - for (var i = 0; i < LENGTH; i++) { - var x = newTarget.readDoubleBE(i * 8) - } -}) -.add('OldBuffer#readDoubleBE', function () { - for (var i = 0; i < LENGTH; i++) { - var x = oldTarget.readDoubleBE(i * 8) - } -}) -.add('Buffer#readDoubleBE', function () { - for (var i = 0; i < LENGTH; i++) { - var x = nodeTarget.readDoubleBE(i * 8) - } -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) -.on('complete', function () { - console.log('Fastest is ' + this.filter('fastest').pluck('name')) -}) -.run({ 'async': true }) +for (var i = 0; i < LENGTH; i++) { + dataview.setFloat64(i * 8, 97.1919 + i) +} + +suite + .add('BrowserBuffer#readDoubleBE', function () { + for (var i = 0; i < LENGTH; i++) { + var x = browserBuffer.readDoubleBE(i * 8) + } + }) + .add('DataView#getFloat64', function () { + for (var i = 0; i < LENGTH; i++) { + var x = dataview.getFloat64(i * 8) + } + }) + +if (!process.browser) suite + .add('NodeBuffer#readDoubleBE', function () { + for (var i = 0; i < LENGTH; i++) { + var x = nodeBuffer.readDoubleBE(i * 8) + } + }) diff --git a/perf/comparison/readFloatBE.js b/perf/comparison/readFloatBE.js index a8d492c..c3aec08 100644 --- a/perf/comparison/readFloatBE.js +++ b/perf/comparison/readFloatBE.js @@ -1,43 +1,39 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() +var BrowserBuffer = require('../../').Buffer // (this module) +var util = require('./util') +var suite = util.suite() -global.NewBuffer = require('../../').Buffer // native-buffer-browserify -global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify +var LENGTH = 160 -var LENGTH = 10 +var browserBuffer = new BrowserBuffer(LENGTH * 4) +var typedarray = new Uint8Array(LENGTH * 4) +var dataview = new DataView(typedarray.buffer) +var nodeBuffer = new Buffer(LENGTH * 4) -var newTarget = NewBuffer(LENGTH * 4) -var oldTarget = OldBuffer(LENGTH * 4) -var nodeTarget = Buffer(LENGTH * 4) - -;[newTarget, oldTarget, nodeTarget].forEach(function (buf) { +;[browserBuffer, nodeBuffer].forEach(function (buf) { for (var i = 0; i < LENGTH; i++) { buf.writeFloatBE(97.1919 + i, i * 4) } }) -suite.add('NewBuffer#readFloatBE', function () { - for (var i = 0; i < LENGTH; i++) { - var x = newTarget.readFloatBE(i * 4) - } -}) -.add('OldBuffer#readFloatBE', function () { - for (var i = 0; i < LENGTH; i++) { - var x = oldTarget.readFloatBE(i * 4) - } -}) -.add('Buffer#readFloatBE', function () { - for (var i = 0; i < LENGTH; i++) { - var x = nodeTarget.readFloatBE(i * 4) - } -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) -.on('complete', function () { - console.log('Fastest is ' + this.filter('fastest').pluck('name')) -}) -.run({ 'async': true }) +for (var i = 0; i < LENGTH; i++) { + dataview.setFloat32(i * 4, 97.1919 + i) +} + +suite + .add('BrowserBuffer#readFloatBE', function () { + for (var i = 0; i < LENGTH; i++) { + var x = browserBuffer.readFloatBE(i * 4) + } + }) + .add('DataView#getFloat32', function () { + for (var i = 0; i < LENGTH; i++) { + var x = dataview.getFloat32(i * 4) + } + }) + +if (!process.browser) suite + .add('NodeBuffer#readFloatBE', function () { + for (var i = 0; i < LENGTH; i++) { + var x = nodeBuffer.readFloatBE(i * 4) + } + }) diff --git a/perf/comparison/readUInt32LE.js b/perf/comparison/readUInt32LE.js index 3ea4f17..55a3365 100644 --- a/perf/comparison/readUInt32LE.js +++ b/perf/comparison/readUInt32LE.js @@ -1,43 +1,39 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() +var BrowserBuffer = require('../../').Buffer // (this module) +var util = require('./util') +var suite = util.suite() -global.NewBuffer = require('../../').Buffer // native-buffer-browserify -global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify +var LENGTH = 160 -var LENGTH = 20 +var browserBuffer = new BrowserBuffer(LENGTH * 4) +var typedarray = new Uint8Array(LENGTH * 4) +var dataview = new DataView(typedarray.buffer) +var nodeBuffer = new Buffer(LENGTH * 4) -var newTarget = NewBuffer(LENGTH * 4) -var oldTarget = OldBuffer(LENGTH * 4) -var nodeTarget = Buffer(LENGTH * 4) - -;[newTarget, oldTarget, nodeTarget].forEach(function (buf) { +;[browserBuffer, nodeBuffer].forEach(function (buf) { for (var i = 0; i < LENGTH; i++) { buf.writeUInt32LE(7000 + i, i * 4) } }) -suite.add('NewBuffer#readUInt32LE', function () { - for (var i = 0; i < LENGTH; i++) { - var x = newTarget.readUInt32LE(i * 4) - } -}) -.add('OldBuffer#readUInt32LE', function () { - for (var i = 0; i < LENGTH; i++) { - var x = oldTarget.readUInt32LE(i * 4) - } -}) -.add('Buffer#readUInt32LE', function () { - for (var i = 0; i < LENGTH; i++) { - var x = nodeTarget.readUInt32LE(i * 4) - } -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) -.on('complete', function () { - console.log('Fastest is ' + this.filter('fastest').pluck('name')) -}) -.run({ 'async': true }) +for (var i = 0; i < LENGTH; i++) { + dataview.setUint32(i * 4, 7000 + i) +} + +suite + .add('BrowserBuffer#readUInt32LE', function () { + for (var i = 0; i < LENGTH; i++) { + var x = browserBuffer.readUInt32LE(i * 4) + } + }) + .add('DataView#getUint32', function () { + for (var i = 0; i < LENGTH; i++) { + var x = dataview.getUint32(i * 4, true) + } + }) + +if (!process.browser) suite + .add('NodeBuffer#readUInt32LE', function () { + for (var i = 0; i < LENGTH; i++) { + var x = nodeBuffer.readUInt32LE(i * 4) + } + }) diff --git a/perf/comparison/slice.js b/perf/comparison/slice.js index d951fcf..d07dc12 100644 --- a/perf/comparison/slice.js +++ b/perf/comparison/slice.js @@ -1,31 +1,22 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() +var BrowserBuffer = require('../../').Buffer // (this module) +var util = require('./util') +var suite = util.suite() -global.NewBuffer = require('../../').Buffer // native-buffer-browserify -global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify +var LENGTH = 160 -var LENGTH = 16 +var browserBuffer = new BrowserBuffer(LENGTH) +var typedarray = new Uint8Array(LENGTH) +var nodeBuffer = new Buffer(LENGTH) -var newBuf = NewBuffer(LENGTH) -var oldBuf = OldBuffer(LENGTH) -var nodeBuf = Buffer(LENGTH) +suite + .add('BrowserBuffer#slice', function () { + var x = browserBuffer.slice(4) + }) + .add('Uint8Array#subarray', function () { + var x = typedarray.subarray(4) + }) -suite.add('NewBuffer#slice', function () { - var x = newBuf.slice(4) -}) -.add('OldBuffer#slice', function () { - var x = oldBuf.slice(4) -}) -.add('Buffer#slice', function () { - var x = nodeBuf.slice(4) -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) -.on('complete', function () { - console.log('Fastest is ' + this.filter('fastest').pluck('name')) -}) -.run({ 'async': true }) \ No newline at end of file +if (!process.browser) suite + .add('NodeBuffer#slice', function () { + var x = nodeBuffer.slice(4) + }) diff --git a/perf/comparison/util.js b/perf/comparison/util.js new file mode 100644 index 0000000..ffd6cbe --- /dev/null +++ b/perf/comparison/util.js @@ -0,0 +1,19 @@ +var benchmark = require('benchmark') + +exports.suite = function () { + var suite = new benchmark.Suite() + process.nextTick(function () { + suite + .on('error', function (event) { + console.error(event.target.error.stack) + }) + .on('cycle', function (event) { + console.log(String(event.target)) + }) + .on('complete', function () { + console.log('Fastest is ' + this.filter('fastest').pluck('name')) + }) + .run({ async: true }) + }) + return suite +} diff --git a/perf/comparison/writeFloatBE.js b/perf/comparison/writeFloatBE.js index 29f48e9..0b10d7f 100644 --- a/perf/comparison/writeFloatBE.js +++ b/perf/comparison/writeFloatBE.js @@ -1,37 +1,29 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() +var BrowserBuffer = require('../../').Buffer // (this module) +var util = require('./util') +var suite = util.suite() -global.NewBuffer = require('../../').Buffer // native-buffer-browserify -global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify +var LENGTH = 160 -var LENGTH = 10 +var browserBuffer = new BrowserBuffer(LENGTH * 4) +var typedarray = new Uint8Array(LENGTH * 4) +var dataview = new DataView(typedarray.buffer) +var nodeBuffer = new Buffer(LENGTH * 4) -var newTarget = NewBuffer(LENGTH * 4) -var oldTarget = OldBuffer(LENGTH * 4) -var nodeTarget = Buffer(LENGTH * 4) +suite + .add('BrowserBuffer#writeFloatBE', function () { + for (var i = 0; i < LENGTH; i++) { + browserBuffer.writeFloatBE(97.1919 + i, i * 4) + } + }) + .add('DataView#setFloat32', function () { + for (var i = 0; i < LENGTH; i++) { + dataview.setFloat32(i * 4, 97.1919 + i) + } + }) -suite.add('NewBuffer#writeFloatBE', function () { - for (var i = 0; i < LENGTH; i++) { - newTarget.writeFloatBE(97.1919 + i, i * 4) - } -}) -.add('OldBuffer#writeFloatBE', function () { - for (var i = 0; i < LENGTH; i++) { - oldTarget.writeFloatBE(97.1919 + i, i * 4) - } -}) -.add('Buffer#writeFloatBE', function () { - for (var i = 0; i < LENGTH; i++) { - nodeTarget.writeFloatBE(97.1919 + i, i * 4) - } -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) -.on('complete', function () { - console.log('Fastest is ' + this.filter('fastest').pluck('name')) -}) -.run({ 'async': true }) +if (!process.browser) suite + .add('NodeBuffer#writeFloatBE', function () { + for (var i = 0; i < LENGTH; i++) { + nodeBuffer.writeFloatBE(97.1919 + i, i * 4) + } + }) diff --git a/perf/solo/bracket-notation.js b/perf/solo/bracket-notation.js deleted file mode 100644 index e43a48b..0000000 --- a/perf/solo/bracket-notation.js +++ /dev/null @@ -1,22 +0,0 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() - -global.NewBuffer = require('../../').Buffer // native-buffer-browserify - -var LENGTH = 50 - -var newTarget = NewBuffer(LENGTH) - -suite.add('NewBuffer#bracket-notation', function () { - for (var i = 0; i < LENGTH; i++) { - newTarget[i] = i + 97 - } -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) - -.run({ 'async': true }) diff --git a/perf/solo/concat.js b/perf/solo/concat.js deleted file mode 100644 index 4e8795f..0000000 --- a/perf/solo/concat.js +++ /dev/null @@ -1,27 +0,0 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() - -global.NewBuffer = require('../../').Buffer // native-buffer-browserify - -var LENGTH = 16 - -var newBuf = NewBuffer(LENGTH) -var newBuf2 = NewBuffer(LENGTH) - -;[newBuf, newBuf2].forEach(function (buf) { - for (var i = 0; i < LENGTH; i++) { - buf[i] = 42 - } -}) - -suite.add('NewBuffer#concat', function () { - var x = Buffer.concat([newBuf, newBuf2]) -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) - -.run({ 'async': true }) \ No newline at end of file diff --git a/perf/solo/copy.js b/perf/solo/copy.js deleted file mode 100644 index 5b167c5..0000000 --- a/perf/solo/copy.js +++ /dev/null @@ -1,21 +0,0 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() - -global.NewBuffer = require('../../').Buffer // native-buffer-browserify - -var LENGTH = 10 - -var newSubject = NewBuffer(LENGTH) -var newTarget = NewBuffer(LENGTH) - -suite.add('NewBuffer#copy', function () { - newSubject.copy(newTarget) -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) - -.run({ 'async': true }) \ No newline at end of file diff --git a/perf/solo/index.html b/perf/solo/index.html deleted file mode 100644 index ebd6fcf..0000000 --- a/perf/solo/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/perf/solo/new.js b/perf/solo/new.js deleted file mode 100644 index 4981d72..0000000 --- a/perf/solo/new.js +++ /dev/null @@ -1,21 +0,0 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() - -global.NewBuffer = require('../../').Buffer // native-buffer-browserify - -var LENGTH = 10 - -suite.add('NewBuffer#new', function () { - var buf = NewBuffer(LENGTH) -}) -.add('Uint8Array#new', function () { - var buf = new Uint8Array(LENGTH) -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) - -.run({ 'async': true }) \ No newline at end of file diff --git a/perf/solo/readDoubleBE.js b/perf/solo/readDoubleBE.js deleted file mode 100644 index 20c5b3c..0000000 --- a/perf/solo/readDoubleBE.js +++ /dev/null @@ -1,26 +0,0 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() - -global.NewBuffer = require('../../').Buffer // native-buffer-browserify - -var LENGTH = 10 - -var newTarget = NewBuffer(LENGTH * 8) - -for (var i = 0; i < LENGTH; i++) { - newTarget.writeDoubleBE(97.1919 + i, i * 8) -} - -suite.add('NewBuffer#readDoubleBE', function () { - for (var i = 0; i < LENGTH; i++) { - var x = newTarget.readDoubleBE(i * 8) - } -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) - -.run({ 'async': true }) diff --git a/perf/solo/readFloatBE.js b/perf/solo/readFloatBE.js deleted file mode 100644 index 732534c..0000000 --- a/perf/solo/readFloatBE.js +++ /dev/null @@ -1,26 +0,0 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() - -global.NewBuffer = require('../../').Buffer // native-buffer-browserify - -var LENGTH = 10 - -var newTarget = NewBuffer(LENGTH * 4) - -for (var i = 0; i < LENGTH; i++) { - newTarget.writeFloatBE(97.1919 + i, i * 4) -} - -suite.add('NewBuffer#readFloatBE', function () { - for (var i = 0; i < LENGTH; i++) { - var x = newTarget.readFloatBE(i * 4) - } -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) - -.run({ 'async': true }) diff --git a/perf/solo/readUInt32BE.js b/perf/solo/readUInt32BE.js deleted file mode 100644 index 1e2675e..0000000 --- a/perf/solo/readUInt32BE.js +++ /dev/null @@ -1,26 +0,0 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() - -global.NewBuffer = require('../../').Buffer // native-buffer-browserify - -var LENGTH = 20 - -var newTarget = NewBuffer(LENGTH * 4) - -for (var i = 0; i < LENGTH; i++) { - newTarget.writeUInt32LE(7000 + i, i * 4) -} - -suite.add('NewBuffer#readUInt32BE', function () { - for (var i = 0; i < LENGTH; i++) { - var x = newTarget.readUInt32BE(i * 4) - } -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) - -.run({ 'async': true }) diff --git a/perf/solo/readUInt32LE.js b/perf/solo/readUInt32LE.js deleted file mode 100644 index 4c4f8f7..0000000 --- a/perf/solo/readUInt32LE.js +++ /dev/null @@ -1,26 +0,0 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() - -global.NewBuffer = require('../../').Buffer // native-buffer-browserify - -var LENGTH = 20 - -var newTarget = NewBuffer(LENGTH * 4) - -for (var i = 0; i < LENGTH; i++) { - newTarget.writeUInt32LE(7000 + i, i * 4) -} - -suite.add('NewBuffer#readUInt32LE', function () { - for (var i = 0; i < LENGTH; i++) { - var x = newTarget.readUInt32LE(i * 4) - } -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) - -.run({ 'async': true }) diff --git a/perf/solo/slice.js b/perf/solo/slice.js deleted file mode 100644 index 493fae1..0000000 --- a/perf/solo/slice.js +++ /dev/null @@ -1,20 +0,0 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() - -global.NewBuffer = require('../../').Buffer // native-buffer-browserify - -var LENGTH = 16 - -var newBuf = NewBuffer(LENGTH) - -suite.add('NewBuffer#slice', function () { - var x = newBuf.slice(4) -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) - -.run({ 'async': true }) \ No newline at end of file diff --git a/perf/solo/writeFloatBE.js b/perf/solo/writeFloatBE.js deleted file mode 100644 index 377b162..0000000 --- a/perf/solo/writeFloatBE.js +++ /dev/null @@ -1,22 +0,0 @@ -var benchmark = require('benchmark') -var suite = new benchmark.Suite() - -global.NewBuffer = require('../../').Buffer // native-buffer-browserify - -var LENGTH = 10 - -var newTarget = NewBuffer(LENGTH * 4) - -suite.add('NewBuffer#writeFloatBE', function () { - for (var i = 0; i < LENGTH; i++) { - newTarget.writeFloatBE(97.1919 + i, i * 4) - } -}) -.on('error', function (event) { - console.error(event.target.error.stack) -}) -.on('cycle', function (event) { - console.log(String(event.target)) -}) - -.run({ 'async': true })