From: Feross Aboukhadijeh Date: Mon, 18 Nov 2013 13:07:36 +0000 (-0800) Subject: add performance tests X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=35dffbb7e73ea540aa5a9559e1df59d91ca00485;p=buffer.git add performance tests --- diff --git a/perf/bracket-notation.js b/perf/bracket-notation.js new file mode 100644 index 0000000..4595fbd --- /dev/null +++ b/perf/bracket-notation.js @@ -0,0 +1,37 @@ +var benchmark = require('benchmark') +var suite = new benchmark.Suite() + +global.NewBuffer = require('../').Buffer // buffer-browserify-fast +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/concat.js b/perf/concat.js new file mode 100644 index 0000000..7907bb8 --- /dev/null +++ b/perf/concat.js @@ -0,0 +1,40 @@ +var benchmark = require('benchmark') +var suite = new benchmark.Suite() + +global.NewBuffer = require('../').Buffer // buffer-browserify-fast +global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify + +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) { + for (var i = 0; i < LENGTH; i++) { + buf[i] = 42 + } +}) + +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 diff --git a/perf/copy.js b/perf/copy.js new file mode 100644 index 0000000..2c1cf38 --- /dev/null +++ b/perf/copy.js @@ -0,0 +1,35 @@ +var benchmark = require('benchmark') +var suite = new benchmark.Suite() + +global.NewBuffer = require('../').Buffer // buffer-browserify-fast +global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify + +var LENGTH = 10 + +var newSubject = NewBuffer(LENGTH) +var oldSubject = OldBuffer(LENGTH) +var nodeSubject = Buffer(LENGTH) + +var newTarget = NewBuffer(LENGTH) +var oldTarget = OldBuffer(LENGTH) +var nodeTarget = Buffer(LENGTH) + +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 diff --git a/perf/index.html b/perf/index.html new file mode 100644 index 0000000..ebd6fcf --- /dev/null +++ b/perf/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/perf/new.js b/perf/new.js new file mode 100644 index 0000000..2e0768a --- /dev/null +++ b/perf/new.js @@ -0,0 +1,30 @@ +var benchmark = require('benchmark') +var suite = new benchmark.Suite() + +global.NewBuffer = require('../').Buffer // buffer-browserify-fast +global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify + +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 diff --git a/perf/readDoubleBE.js b/perf/readDoubleBE.js new file mode 100644 index 0000000..0dfb3b1 --- /dev/null +++ b/perf/readDoubleBE.js @@ -0,0 +1,43 @@ +var benchmark = require('benchmark') +var suite = new benchmark.Suite() + +global.NewBuffer = require('../').Buffer // buffer-browserify-fast +global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify + +var LENGTH = 10 + +var newTarget = NewBuffer(LENGTH * 8) +var oldTarget = OldBuffer(LENGTH * 8) +var nodeTarget = Buffer(LENGTH * 8) + +;[newTarget, oldTarget, nodeTarget].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 }) diff --git a/perf/readFloatBE.js b/perf/readFloatBE.js new file mode 100644 index 0000000..c7d5da8 --- /dev/null +++ b/perf/readFloatBE.js @@ -0,0 +1,43 @@ +var benchmark = require('benchmark') +var suite = new benchmark.Suite() + +global.NewBuffer = require('../').Buffer // buffer-browserify-fast +global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify + +var LENGTH = 10 + +var newTarget = NewBuffer(LENGTH * 4) +var oldTarget = OldBuffer(LENGTH * 4) +var nodeTarget = Buffer(LENGTH * 4) + +;[newTarget, oldTarget, nodeTarget].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 }) diff --git a/perf/readUInt32LE.js b/perf/readUInt32LE.js new file mode 100644 index 0000000..bb2fe49 --- /dev/null +++ b/perf/readUInt32LE.js @@ -0,0 +1,43 @@ +var benchmark = require('benchmark') +var suite = new benchmark.Suite() + +global.NewBuffer = require('../').Buffer // buffer-browserify-fast +global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify + +var LENGTH = 20 + +var newTarget = NewBuffer(LENGTH * 4) +var oldTarget = OldBuffer(LENGTH * 4) +var nodeTarget = Buffer(LENGTH * 4) + +;[newTarget, oldTarget, nodeTarget].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 }) diff --git a/perf/slice.js b/perf/slice.js new file mode 100644 index 0000000..5485999 --- /dev/null +++ b/perf/slice.js @@ -0,0 +1,31 @@ +var benchmark = require('benchmark') +var suite = new benchmark.Suite() + +global.NewBuffer = require('../').Buffer // buffer-browserify-fast +global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify + +var LENGTH = 16 + +var newBuf = NewBuffer(LENGTH) +var oldBuf = OldBuffer(LENGTH) +var nodeBuf = Buffer(LENGTH) + +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 diff --git a/perf/writeFloatBE.js b/perf/writeFloatBE.js new file mode 100644 index 0000000..4b63a54 --- /dev/null +++ b/perf/writeFloatBE.js @@ -0,0 +1,37 @@ +var benchmark = require('benchmark') +var suite = new benchmark.Suite() + +global.NewBuffer = require('../').Buffer // buffer-browserify-fast +global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify + +var LENGTH = 10 + +var newTarget = NewBuffer(LENGTH * 4) +var oldTarget = OldBuffer(LENGTH * 4) +var nodeTarget = Buffer(LENGTH * 4) + +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 })