]> zoso.dev Git - buffer.git/commitdiff
add solo performance tests
authorFeross Aboukhadijeh <feross@feross.org>
Sat, 28 Dec 2013 05:40:46 +0000 (21:40 -0800)
committerFeross Aboukhadijeh <feross@feross.org>
Sat, 28 Dec 2013 05:40:46 +0000 (21:40 -0800)
21 files changed:
package.json
perf/comparison/bracket-notation.js [new file with mode: 0644]
perf/comparison/concat.js [moved from perf/concat.js with 91% similarity]
perf/comparison/copy.js [moved from perf/copy.js with 89% similarity]
perf/comparison/index.html [moved from perf/index.html with 100% similarity]
perf/comparison/new.js [moved from perf/new.js with 87% similarity]
perf/comparison/readDoubleBE.js [moved from perf/readDoubleBE.js with 93% similarity]
perf/comparison/readFloatBE.js [moved from perf/readFloatBE.js with 93% similarity]
perf/comparison/readUInt32LE.js [moved from perf/readUInt32LE.js with 93% similarity]
perf/comparison/slice.js [moved from perf/slice.js with 88% similarity]
perf/comparison/writeFloatBE.js [moved from perf/writeFloatBE.js with 93% similarity]
perf/solo/bracket-notation.js [new file with mode: 0644]
perf/solo/concat.js [new file with mode: 0644]
perf/solo/copy.js [new file with mode: 0644]
perf/solo/index.html [new file with mode: 0644]
perf/solo/new.js [new file with mode: 0644]
perf/solo/readDoubleBE.js [new file with mode: 0644]
perf/solo/readFloatBE.js [new file with mode: 0644]
perf/solo/readUInt32LE.js [new file with mode: 0644]
perf/solo/slice.js [new file with mode: 0644]
perf/solo/writeFloatBE.js [new file with mode: 0644]

index 2e52ff7c39a00ac508981dafd8ca68d772c02823..ce71382f68edddba9a64a695f4122f52f7764e1e 100644 (file)
@@ -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 (file)
index 0000000..afd69eb
--- /dev/null
@@ -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 })
similarity index 91%
rename from perf/concat.js
rename to perf/comparison/concat.js
index d597dbfcdc0c3fb7f7a959886295678761c665d0..c8fb193e32f9ff85c75df54cdc7cbbfaf71814eb 100644 (file)
@@ -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
similarity index 89%
rename from perf/copy.js
rename to perf/comparison/copy.js
index c4cfbf1be28434c38498cade64208983abb466e7..0f2b0df9650c1bd8f2347c7a4a47523b72bf61db 100644 (file)
@@ -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
similarity index 100%
rename from perf/index.html
rename to perf/comparison/index.html
similarity index 87%
rename from perf/new.js
rename to perf/comparison/new.js
index ca289509af0b3ee48c0c092baa2b1e551b048c2f..7751533658b5770fda9c22c55850051fcde2f3fc 100644 (file)
@@ -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
similarity index 93%
rename from perf/readDoubleBE.js
rename to perf/comparison/readDoubleBE.js
index 22180799108f8da2fa86ce69655b609d5050366a..828bc37e9697ce3c418a12146c2fbaea5144d86f 100644 (file)
@@ -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
similarity index 93%
rename from perf/readFloatBE.js
rename to perf/comparison/readFloatBE.js
index 1fa7bd59bce9948132216509c14fdfcc6e8b5358..a8d492cbf884ffa470855f91fe421be59c0fb78a 100644 (file)
@@ -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
similarity index 93%
rename from perf/readUInt32LE.js
rename to perf/comparison/readUInt32LE.js
index 3fe5a17302af388e69ba20e7672b253bceba1648..3ea4f17703b6f53fcb53f040a13c9a02dfc25978 100644 (file)
@@ -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
similarity index 88%
rename from perf/slice.js
rename to perf/comparison/slice.js
index 274869c8a8c4b87ef75d807d610212ccd7c48971..d951fcfd47d9594c941de10f3802817d84e2fa86 100644 (file)
@@ -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
similarity index 93%
rename from perf/writeFloatBE.js
rename to perf/comparison/writeFloatBE.js
index d819bc80f71efe6cad2508f06060819f5f79b1c5..29f48e9e3dee807292c4bb9d0f56a73192352960 100644 (file)
@@ -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 (file)
index 0000000..e43a48b
--- /dev/null
@@ -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 (file)
index 0000000..4e8795f
--- /dev/null
@@ -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 (file)
index 0000000..5b167c5
--- /dev/null
@@ -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 (file)
index 0000000..ebd6fcf
--- /dev/null
@@ -0,0 +1 @@
+<script src='bundle.js'></script>
\ No newline at end of file
diff --git a/perf/solo/new.js b/perf/solo/new.js
new file mode 100644 (file)
index 0000000..4981d72
--- /dev/null
@@ -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 (file)
index 0000000..20c5b3c
--- /dev/null
@@ -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 (file)
index 0000000..732534c
--- /dev/null
@@ -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 (file)
index 0000000..4c4f8f7
--- /dev/null
@@ -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 (file)
index 0000000..493fae1
--- /dev/null
@@ -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 (file)
index 0000000..377b162
--- /dev/null
@@ -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 })