summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-09-07 16:30:17 -0700
committerRyan Dahl <ry@tinyclouds.org>2010-09-09 11:03:50 -0700
commitff027d571bdf4e006717747089aa4015d9bbd9ed (patch)
tree3fe6c0407f9a35bc913cd46a503faed961d95053 /benchmark
parent17ba821e6093c0d36d2117cab41b0a860bfaa805 (diff)
downloadnode-ff027d571bdf4e006717747089aa4015d9bbd9ed.tar.gz
Update fast buffer benchmarks
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/buffer_creation.js6
-rw-r--r--benchmark/fast_buffer2.js42
-rw-r--r--benchmark/fast_buffer2_creation.js6
-rw-r--r--benchmark/fast_buffer_creation.js4
4 files changed, 55 insertions, 3 deletions
diff --git a/benchmark/buffer_creation.js b/benchmark/buffer_creation.js
index 44ae32e31..3bc711e3b 100644
--- a/benchmark/buffer_creation.js
+++ b/benchmark/buffer_creation.js
@@ -1,6 +1,6 @@
+SlowBuffer = require('buffer').SlowBuffer;
-
-for (var i = 0; i < 9e7; i++) {
- b = new Buffer(10);
+for (var i = 0; i < 1e6; i++) {
+ b = new SlowBuffer(10);
b[1] = 2
}
diff --git a/benchmark/fast_buffer2.js b/benchmark/fast_buffer2.js
new file mode 100644
index 000000000..861ae3baa
--- /dev/null
+++ b/benchmark/fast_buffer2.js
@@ -0,0 +1,42 @@
+var SlowBuffer = require('buffer').SlowBuffer;
+var POOLSIZE = 8*1024;
+var pool;
+
+function allocPool () {
+ pool = new SlowBuffer(POOLSIZE);
+ pool.used = 0;
+}
+
+function FastBuffer (length) {
+ this.length = length;
+
+ if (length > POOLSIZE) {
+ // Big buffer, just alloc one.
+ this.parent = new Buffer(length);
+ this.offset = 0;
+ } else {
+ // Small buffer.
+ if (!pool || pool.length - pool.used < length) allocPool();
+ this.parent = pool;
+ this.offset = pool.used;
+ pool.used += length;
+ }
+
+ // HERE HERE HERE
+ SlowBuffer.makeFastBuffer(this.parent, this, this.offset, this.length);
+}
+
+exports.FastBuffer = FastBuffer;
+
+FastBuffer.prototype.get = function (i) {
+ if (i < 0 || i >= this.length) throw new Error("oob");
+ return this.parent[this.offset + i];
+};
+
+FastBuffer.prototype.set = function (i, v) {
+ if (i < 0 || i >= this.length) throw new Error("oob");
+ return this.parent[this.offset + i] = v;
+};
+
+// TODO define slice, toString, write, etc.
+// slice should not use c++
diff --git a/benchmark/fast_buffer2_creation.js b/benchmark/fast_buffer2_creation.js
new file mode 100644
index 000000000..877f5695d
--- /dev/null
+++ b/benchmark/fast_buffer2_creation.js
@@ -0,0 +1,6 @@
+
+FastBuffer = require('./fast_buffer2').FastBuffer;
+for (var i = 0; i < 1e6; i++) {
+ b = new FastBuffer(10);
+ b[1] = 2;
+}
diff --git a/benchmark/fast_buffer_creation.js b/benchmark/fast_buffer_creation.js
new file mode 100644
index 000000000..fbd0c7579
--- /dev/null
+++ b/benchmark/fast_buffer_creation.js
@@ -0,0 +1,4 @@
+for (var i = 0; i < 1e6; i++) {
+ b = new Buffer(10);
+ b[1] = 2;
+}