From: Feross Aboukhadijeh Date: Sat, 28 Dec 2013 05:40:46 +0000 (-0800) Subject: add solo performance tests X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=a54684a0511ce0eccd09629da574dc25a6cec3a2;p=buffer.git add solo performance tests --- diff --git a/package.json b/package.json index 2e52ff7..ce71382 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ ], "scripts": { "test": "tape test/*.js", - "perf": "browserify --debug perf/concat.js > perf/bundle.js && open perf/index.html" + "perf": "cd perf/solo && browserify --debug concat.js > bundle.js && open index.html" }, "license": "MIT" } diff --git a/perf/comparison/bracket-notation.js b/perf/comparison/bracket-notation.js new file mode 100644 index 0000000..afd69eb --- /dev/null +++ b/perf/comparison/bracket-notation.js @@ -0,0 +1,37 @@ +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/concat.js b/perf/comparison/concat.js similarity index 91% rename from perf/concat.js rename to perf/comparison/concat.js index d597dbf..c8fb193 100644 --- a/perf/concat.js +++ b/perf/comparison/concat.js @@ -1,7 +1,7 @@ var benchmark = require('benchmark') var suite = new benchmark.Suite() -global.NewBuffer = require('../').Buffer // native-buffer-browserify +global.NewBuffer = require('../../').Buffer // native-buffer-browserify global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify var LENGTH = 16 diff --git a/perf/copy.js b/perf/comparison/copy.js similarity index 89% rename from perf/copy.js rename to perf/comparison/copy.js index c4cfbf1..0f2b0df 100644 --- a/perf/copy.js +++ b/perf/comparison/copy.js @@ -1,7 +1,7 @@ var benchmark = require('benchmark') var suite = new benchmark.Suite() -global.NewBuffer = require('../').Buffer // native-buffer-browserify +global.NewBuffer = require('../../').Buffer // native-buffer-browserify global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify var LENGTH = 10 diff --git a/perf/index.html b/perf/comparison/index.html similarity index 100% rename from perf/index.html rename to perf/comparison/index.html diff --git a/perf/new.js b/perf/comparison/new.js similarity index 87% rename from perf/new.js rename to perf/comparison/new.js index ca28950..7751533 100644 --- a/perf/new.js +++ b/perf/comparison/new.js @@ -1,7 +1,7 @@ var benchmark = require('benchmark') var suite = new benchmark.Suite() -global.NewBuffer = require('../').Buffer // native-buffer-browserify +global.NewBuffer = require('../../').Buffer // native-buffer-browserify global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify var LENGTH = 10 diff --git a/perf/readDoubleBE.js b/perf/comparison/readDoubleBE.js similarity index 93% rename from perf/readDoubleBE.js rename to perf/comparison/readDoubleBE.js index 2218079..828bc37 100644 --- a/perf/readDoubleBE.js +++ b/perf/comparison/readDoubleBE.js @@ -1,7 +1,7 @@ var benchmark = require('benchmark') var suite = new benchmark.Suite() -global.NewBuffer = require('../').Buffer // native-buffer-browserify +global.NewBuffer = require('../../').Buffer // native-buffer-browserify global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify var LENGTH = 10 diff --git a/perf/readFloatBE.js b/perf/comparison/readFloatBE.js similarity index 93% rename from perf/readFloatBE.js rename to perf/comparison/readFloatBE.js index 1fa7bd5..a8d492c 100644 --- a/perf/readFloatBE.js +++ b/perf/comparison/readFloatBE.js @@ -1,7 +1,7 @@ var benchmark = require('benchmark') var suite = new benchmark.Suite() -global.NewBuffer = require('../').Buffer // native-buffer-browserify +global.NewBuffer = require('../../').Buffer // native-buffer-browserify global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify var LENGTH = 10 diff --git a/perf/readUInt32LE.js b/perf/comparison/readUInt32LE.js similarity index 93% rename from perf/readUInt32LE.js rename to perf/comparison/readUInt32LE.js index 3fe5a17..3ea4f17 100644 --- a/perf/readUInt32LE.js +++ b/perf/comparison/readUInt32LE.js @@ -1,7 +1,7 @@ var benchmark = require('benchmark') var suite = new benchmark.Suite() -global.NewBuffer = require('../').Buffer // native-buffer-browserify +global.NewBuffer = require('../../').Buffer // native-buffer-browserify global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify var LENGTH = 20 diff --git a/perf/slice.js b/perf/comparison/slice.js similarity index 88% rename from perf/slice.js rename to perf/comparison/slice.js index 274869c..d951fcf 100644 --- a/perf/slice.js +++ b/perf/comparison/slice.js @@ -1,7 +1,7 @@ var benchmark = require('benchmark') var suite = new benchmark.Suite() -global.NewBuffer = require('../').Buffer // native-buffer-browserify +global.NewBuffer = require('../../').Buffer // native-buffer-browserify global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify var LENGTH = 16 diff --git a/perf/writeFloatBE.js b/perf/comparison/writeFloatBE.js similarity index 93% rename from perf/writeFloatBE.js rename to perf/comparison/writeFloatBE.js index d819bc8..29f48e9 100644 --- a/perf/writeFloatBE.js +++ b/perf/comparison/writeFloatBE.js @@ -1,7 +1,7 @@ var benchmark = require('benchmark') var suite = new benchmark.Suite() -global.NewBuffer = require('../').Buffer // native-buffer-browserify +global.NewBuffer = require('../../').Buffer // native-buffer-browserify global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify var LENGTH = 10 diff --git a/perf/solo/bracket-notation.js b/perf/solo/bracket-notation.js new file mode 100644 index 0000000..e43a48b --- /dev/null +++ b/perf/solo/bracket-notation.js @@ -0,0 +1,22 @@ +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 new file mode 100644 index 0000000..4e8795f --- /dev/null +++ b/perf/solo/concat.js @@ -0,0 +1,27 @@ +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 new file mode 100644 index 0000000..5b167c5 --- /dev/null +++ b/perf/solo/copy.js @@ -0,0 +1,21 @@ +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 new file mode 100644 index 0000000..ebd6fcf --- /dev/null +++ b/perf/solo/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/perf/solo/new.js b/perf/solo/new.js new file mode 100644 index 0000000..4981d72 --- /dev/null +++ b/perf/solo/new.js @@ -0,0 +1,21 @@ +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 new file mode 100644 index 0000000..20c5b3c --- /dev/null +++ b/perf/solo/readDoubleBE.js @@ -0,0 +1,26 @@ +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 new file mode 100644 index 0000000..732534c --- /dev/null +++ b/perf/solo/readFloatBE.js @@ -0,0 +1,26 @@ +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/readUInt32LE.js b/perf/solo/readUInt32LE.js new file mode 100644 index 0000000..4c4f8f7 --- /dev/null +++ b/perf/solo/readUInt32LE.js @@ -0,0 +1,26 @@ +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 new file mode 100644 index 0000000..493fae1 --- /dev/null +++ b/perf/solo/slice.js @@ -0,0 +1,20 @@ +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 new file mode 100644 index 0000000..377b162 --- /dev/null +++ b/perf/solo/writeFloatBE.js @@ -0,0 +1,22 @@ +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 })