Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-09-08 03:30:17 +0400
committerRyan Dahl <ry@tinyclouds.org>2010-09-09 22:03:50 +0400
commitff027d571bdf4e006717747089aa4015d9bbd9ed (patch)
tree3fe6c0407f9a35bc913cd46a503faed961d95053 /benchmark/fast_buffer2.js
parent17ba821e6093c0d36d2117cab41b0a860bfaa805 (diff)
Update fast buffer benchmarks
Diffstat (limited to 'benchmark/fast_buffer2.js')
-rw-r--r--benchmark/fast_buffer2.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/benchmark/fast_buffer2.js b/benchmark/fast_buffer2.js
new file mode 100644
index 00000000000..861ae3baae7
--- /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++