Permalink
Browse files

src: improve benchmarks

Hopefully many benchmarks for micro testing will help identify where
problem spots exist in larger applications. Break down of what has been
done:

* removed deprecated benchmarks that are no longer applicable
* rewrote existing benchmarks to be more extensive
* organized benchmarks
  • Loading branch information...
1 parent b7d76a1 commit d41302faa4d236776bc092471543f35349040660 @trevnorris trevnorris committed Jan 16, 2013
View
136 benchmark/_bench_timer.js
@@ -1,7 +1,28 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
/*
- * This is a simple addition to allow for higher resolution timers.
- * It can be used to track time for both synchronous or asynchronous
- * calls. For synchronous calls pass a callback function like so:
+ * This is a simple addition to allow for higher resolution timers. It can be
+ * used to track time for both synchronous or asynchronous calls. For
+ * synchronous calls pass a callback function like so:
*
* var timer = require('./_bench_timer');
*
@@ -11,33 +32,73 @@
* }
* });
*
- * For asynchronous timers just pass the name. Then run it again with
- * the same name to finish it:
+ * For asynchronous timers just pass the name. Then run it again with the same
+ * name to finish it:
*
* timer('checkAsync');
* setTimeout(function() {
* timer('checkAsync');
* }, 300);
*
- * When this happens all currently queued benchmarks will be paused
- * until the asynchronous benchmark has completed.
+ * To use the asynchronous timer for printing itterations over time, pass the
+ * number of ms between log intervals you would like to use as the second
+ * argument. Then call timer.inc(<name>) to increment the internal counter. If
+ * you would like to indicate how many times this counter should log before
+ * stopping, pass a third value. If no third value is passed then the counter
+ * will automatically stop after receiving three 0 counters in a row:
+ *
+ * timer('asyncCounter', 1000);
+ * setInterval(function() {
+ * timer.inc('asyncCounter');
+ * }, 20);
+ *
+ * When asynchronous counters run all currently queued benchmarks will be
+ * paused until the asynchronous benchmark has completed.
+ *
+ * If the benchmark has been run with --expose_gc then the garbage collector
+ * will be run between each test.
+ *
+ * The setTimeout delay can also be changed by passing a value to timer.delay.
*
- * If the benchmark has been run with --expose_gc then the garbage
- * collector will be run between each test.
+ * Pass arguments to timer.parse() and get back an object with the names of each
+ * passed argument.
*
- * The setTimeout delay can also be changed by passing a value to
- * timer.delay.
+ * There is one built in argument that will interact directly with the timer.
+ * `--run` followed by one or more strings will identify to the timer which
+ * tests should be run. All other tests will be dropped. Use like the following:
+ *
+ * node my_bench.js --run 'test1' 'test2'
+ *
+ * Each benchmark should also have a list of all accepted parameters.
+ *
+ * Note: All benchmark parameters need to start with `--`.
*/
var store = {};
+var counter = {};
+var counter_info = {};
var order = [];
+var runQueue = false;
var maxLength = 0;
var processing = false;
var asyncQueue = 0;
var GCd = typeof gc !== 'function' ? false : true;
+var rParse = /^--[^-]/;
-function timer(name, fn) {
+function timer(name, fn, times) {
+ if (runQueue && !runQueue[name]) return;
+ if (typeof fn == 'number') {
+ counter[name] = 0;
+ counter_info[name] = {
+ delay: fn,
+ prevz: 0,
+ times: typeof times != 'undefined' ? times : -1
+ }
+ processing = false;
+ asyncQueue++;
+ setupInterval(name);
+ }
if (maxLength < name.length)
maxLength = name.length;
if (!fn) {
@@ -59,7 +120,36 @@ function timer(name, fn) {
}
}
-timer.delay = 100;
+timer.delay = 300;
+
+timer.parse = function(argv) {
+ var obj = {};
+ var current, i;
+ for (i = 2; i < argv.length; i++) {
+ if (rParse.test(argv[i])) {
+ current = obj[argv[i].substr(2)] = [];
+ } else if (current) {
+ current.push(argv[i]);
+ }
+ }
+ if (obj.run) {
+ runQueue = {};
+ for (i = 0; i < obj.run.length; i++)
+ runQueue[obj.run[i]] = true;
+ }
+ if (obj.len) {
+ obj.len = parseFloat(obj.len);
+ if (!isFinite(obj.len))
+ throw RangeError('Pass numeric value for number of iterations');
+ } else {
+ obj.len = false;
+ }
+ return obj;
+};
+
+timer.inc = function(name) {
+ counter[name]++;
+};
function run() {
if (asyncQueue > 0 || order.length <= 0)
@@ -76,12 +166,30 @@ function run() {
}, timer.delay);
}
+function setupInterval(name) {
+ var val = setInterval(function() {
+ var time = Date.now() - counter_info[name].prevtime;
+ console.log(name + ': ' +
+ (counter[name] / time * 1000).toFixed(2) + '/sec');
+ if (counter[name] === 0)
+ counter_info[name].prevz++;
+ if (counter_info[name].times > 0)
+ counter_info[name].times--;
+ if (counter_info[name].times === 0 || counter_info[name].prevz > 3)
+ return clearInterval(val);
+ counter[name] = 0;
+ counter_info[name]
+ counter_info[name].prevtime = Date.now();
+ }, counter_info[name].delay);
+ counter_info[name].prevtime = Date.now();
+}
+
function displayTime(name, ini) {
name += ': ';
while (name.length < maxLength + 2)
name += ' ';
console.log(name + '%s \u00b5s',
- (~~((ini[0] * 1e6) + (ini[1] / 1e3)))
+ Math.floor((ini[0] * 1e6) + (ini[1] / 1e3))
.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
}
View
76 benchmark/buffer/buffer_class.js
@@ -0,0 +1,76 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+/* Usage:
+ *
+ * --run: specify which test(s) to run
+ * --len: how many itterations each test should run (default: 1e6)
+ * --type: whether to use a 'fast' or 'slow' buffer (default: fast)
+ *
+ * Example:
+ *
+ * node buffer_class.js --run 'byteLength - ascii' --len 1e5 --type slow
+ */
+
+var timer = require('../_bench_timer');
+var parsed = timer.parse(process.argv);
+var Buff = parsed.type == 'slow' ? require('buffer').SlowBuffer : Buffer;
+var LEN = parsed.len || 1e6;
+var str = createString(1e3);
+
+timer('isBuffer - {}', function() {
+ for (var i = 0; i < LEN; i++)
+ Buffer.isBuffer({});
+});
+
+timer('byteLength - utf8', function() {
+ for (var i = 0; i < LEN; i++)
+ Buffer.byteLength(str, 'utf8');
+});
+
+timer('byteLength - ascii', function() {
+ for (var i = 0; i < LEN; i++)
+ Buffer.byteLength(str, 'ascii');
+});
+
+timer('byteLength - hex', function() {
+ for (var i = 0; i < LEN; i++)
+ Buffer.byteLength(str, 'hex');
+});
+
+timer('byteLength - ucs2', function() {
+ for (var i = 0; i < LEN; i++)
+ Buffer.byteLength(str, 'ucs2');
+});
+
+timer('byteLength - base64', function() {
+ for (var i = 0; i < LEN; i++)
+ Buffer.byteLength(str, 'base64');
+});
+
+
+function createString(len) {
+ var str = '\u2803';
+ while (str.length * 2 <= len)
+ str += str;
+ str += str.substr(0, len - str.length);
+ return str;
+}
View
56 benchmark/buffer/buffer_copy.js
@@ -0,0 +1,56 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+/* Usage:
+ *
+ * --run: specify which test(s) to run
+ * --len: how many itterations each test should run (default: 1e6)
+ * --type: whether to use a 'fast' or 'slow' buffer (default: fast)
+ *
+ * Example:
+ *
+ * node buffer_copy.js --run 'fill' --len 1e5 --type slow
+ */
+
+var timer = require('../_bench_timer');
+var parsed = timer.parse(process.argv);
+var Buff = parsed.type == 'slow' ? require('buffer').SlowBuffer : Buffer;
+var LEN = parsed.len || 1e6;
+var buf0 = Buff(1e3);
+var buf1 = Buff(1e3);
+
+buf0.fill(0x61, 0, buf0.length);
+buf1.fill(0x62, 0, buf1.length);
+
+timer('fill', function() {
+ for (var i = 0; i < LEN; i++)
+ buf0.copy(buf1);
+});
+
+timer('fill - seg', function() {
+ for (var i = 0; i < LEN; i++)
+ buf0.copy(buf1, 500);
+});
+
+timer('fill - same', function() {
+ for (var i = 0; i < LEN; i++)
+ buf0.copy(buf0);
+});
View
95 benchmark/buffer/buffer_creation.js
@@ -0,0 +1,95 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+/* Usage:
+ *
+ * --run: specify which test(s) to run
+ * --len: how many itterations each test should run (default: 1e6)
+ *
+ * Example:
+ *
+ * node buffer_creation.js --run 'Buffer - 1' --len 1e5
+ */
+
+var timer = require('../_bench_timer');
+var parsed = timer.parse(process.argv);
+var LEN = parsed.len || 1e6;
+var SlowBuffer = require('buffer').SlowBuffer;
+
+timer('Buffer - 1', function() {
+ for (var i = 0; i < LEN; i++)
+ Buffer(1);
+});
+
+timer('new Buffer - 1', function() {
+ for (var i = 0; i < LEN; i++)
+ new Buffer(1);
+});
+
+timer('Buffer - 100', function() {
+ for (var i = 0; i < LEN; i++)
+ Buffer(100);
+});
+
+timer('new Buffer - 100', function() {
+ for (var i = 0; i < LEN; i++)
+ new Buffer(100);
+});
+
+timer('Buffer - 1000', function() {
+ for (var i = 0; i < LEN; i++)
+ Buffer(1000);
+});
+
+timer('new Buffer - 1000', function() {
+ for (var i = 0; i < LEN; i++)
+ new Buffer(1000);
+});
+
+timer('Buffer - [10]', function() {
+ for (var i = 0; i < LEN; i++)
+ Buffer([0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9]);
+});
+
+timer('Buffer - str', function() {
+ for (var i = 0; i < LEN; i++)
+ Buffer('this is a string for testing', 'utf8');
+});
+
+timer('Buffer - poolSize', function() {
+ for (var i = 0; i < LEN; i++)
+ Buffer(Buffer.poolSize);
+});
+
+timer('SlowBuffer - 10', function() {
+ for (var i = 0; i < LEN; i++)
+ SlowBuffer(10);
+});
+
+timer('SlowBuffer - 100', function() {
+ for (var i = 0; i < LEN; i++)
+ SlowBuffer(100);
+});
+
+timer('SlowBuffer - 1000', function() {
+ for (var i = 0; i < LEN; i++)
+ SlowBuffer(1000);
+});
View
54 benchmark/buffer/buffer_fill.js
@@ -0,0 +1,54 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+/* Usage:
+ *
+ * --run: specify which test(s) to run
+ * --len: how many itterations each test should run (default: 1e6)
+ * --type: whether to use a 'fast' or 'slow' buffer (default: fast)
+ *
+ * Example:
+ *
+ * node buffer_fill.js --run 'fill - 1e2' --len 1e5 --type slow
+ */
+
+var timer = require('../_bench_timer');
+var parsed = timer.parse(process.argv);
+var Buff = parsed.type == 'slow' ? require('buffer').SlowBuffer : Buffer;
+var LEN = parsed.len || 1e6;
+var buf1e2 = Buff(1e2);
+var buf1e4 = Buff(1e4);
+var buf1e5 = Buff(1e5);
+
+timer('fill - 1e2', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e2.fill(10, 0, 10);
+});
+
+timer('fill - 1e4', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e4.fill(10, 0, 10);
+});
+
+timer('fill - 1e5', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e5.fill(10, 0, 10);
+});
View
125 benchmark/buffer/buffer_read.js
@@ -0,0 +1,125 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+/* Usage:
+ *
+ * --run: specify which test(s) to run
+ * --len: how many itterations each test should run (default: 1e6)
+ * --type: whether to use a 'fast' or 'slow' buffer (default: fast)
+ * --noassert: enable noAssert (default: false)
+ *
+ * Example:
+ *
+ * node buffer_read.js --run readUInt8 --len 1e5 --type slow --noassert true
+ */
+
+var timer = require('../_bench_timer');
+var parsed = timer.parse(process.argv);
+var Buff = parsed.type == 'slow' ? require('buffer').SlowBuffer : Buffer;
+var noAssert = parsed.noassert == 'true' ? true : false;
+var LEN = parsed.len || 1e6;
+var buff = Buff(8);
+
+buff.fill(0, 0, buff.length);
+
+timer('readUInt8', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readUInt8(0, noAssert);
+ }
+});
+
+timer('readUInt16LE', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readUInt16LE(0, noAssert);
+ }
+});
+
+timer('readUInt16BE', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readUInt16BE(0, noAssert);
+ }
+});
+
+timer('readUInt32LE', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readUInt32LE(0, noAssert);
+ }
+});
+
+timer('readUInt32BE', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readUInt32BE(0, noAssert);
+ }
+});
+
+timer('readInt8', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readInt8(0, noAssert);
+ }
+});
+
+timer('readInt16LE', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readInt16LE(0, noAssert);
+ }
+});
+
+timer('readInt16BE', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readInt16BE(0, noAssert);
+ }
+});
+
+timer('readInt32LE', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readInt32LE(0, noAssert);
+ }
+});
+
+timer('readInt32BE', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readInt32BE(0, noAssert);
+ }
+});
+
+timer('readFloatLE', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readFloatLE(0, noAssert);
+ }
+});
+
+timer('readFloatBE', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readFloatBE(0, noAssert);
+ }
+});
+
+timer('readDoubleLE', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readDoubleLE(0, noAssert);
+ }
+});
+
+timer('readDoubleBE', function() {
+ for (var i = 0; i < LEN; i++) {
+ buff.readDoubleBE(0, noAssert);
+ }
+});
View
58 benchmark/buffer/buffer_slice.js
@@ -0,0 +1,58 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+/* Usage:
+ *
+ * --run: specify which test(s) to run
+ * --len: how many itterations each test should run (default: 1e6)
+ * --type: whether to use a 'fast' or 'slow' buffer (default: fast)
+ *
+ * Example:
+ *
+ * node buffer_slice.js --run 'slice - 1e2' --len 1e5 --type slow
+ */
+
+var timer = require('../_bench_timer');
+var parsed = timer.parse(process.argv);
+var Buff = parsed.type == 'slow' ? require('buffer').SlowBuffer : Buffer;
+var LEN = parsed.len || 1e6;
+var buf1e2 = new Buff(1e2);
+var buf1e4 = new Buff(1e4);
+
+timer('slice - 1e2', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e2.slice();
+});
+
+timer('slice - 1e2/1,50', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e2.slice(1,50);
+});
+
+timer('slice - 1e4', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e4.slice();
+});
+
+timer('slice - 1e4/1,500', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e4.slice(1,500);
+});
View
48 benchmark/buffer/buffer_tojson.js
@@ -0,0 +1,48 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+/* Usage:
+ *
+ * --run: specify which test(s) to run
+ * --len: how many itterations each test should run (default: 1e6)
+ * --type: whether to use a 'fast' or 'slow' buffer (default: fast)
+ *
+ * Example:
+ *
+ * node buffer_tojson.js --run 'toJSON - 1e2' --len 1e5 --type slow
+ */
+
+var timer = require('../_bench_timer');
+var parsed = timer.parse(process.argv);
+var Buff = parsed.type == 'slow' ? require('buffer').SlowBuffer : Buffer;
+var LEN = parsed.len || 1e6;
+var buf1e2 = Buff(1e2);
+var buf1e3 = Buff(1e3);
+
+timer('toJSON - 1e2', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e2.toJSON();
+});
+
+timer('toJSON - 1e3', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e3.toJSON();
+});
View
91 benchmark/buffer/buffer_tostring.js
@@ -0,0 +1,91 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+/* Usage:
+ *
+ * --run: specify which test(s) to run
+ * --len: how many itterations each test should run (default: 1e6)
+ * --type: whether to use a 'fast' or 'slow' buffer (default: fast)
+ *
+ * Example:
+ *
+ * node buffer_tostring.js --run 'utf8 - 1e2' --len 1e5 --type slow
+ */
+
+var timer = require('../_bench_timer');
+var parsed = timer.parse(process.argv);
+var Buff = parsed.type == 'slow' ? require('buffer').SlowBuffer : Buffer;
+var LEN = parsed.len || 1e6;
+var buf1e2 = Buff(1e2);
+var buf1e4 = Buff(1e4);
+
+buf1e2.fill(0x61, 0, buf1e2.length);
+buf1e4.fill(0x61, 0, buf1e4.length);
+
+timer('utf8 - 1e2', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e2.toString('utf8');
+});
+
+timer('utf8 - 1e4', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e4.toString('utf8');
+});
+
+timer('ascii - 1e2', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e2.toString('ascii');
+});
+
+timer('ascii - 1e4', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e4.toString('ascii');
+});
+
+timer('hex - 1e2', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e2.toString('hex');
+});
+
+timer('hex - 1e4', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e4.toString('hex');
+});
+
+timer('base64 - 1e2', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e2.toString('base64');
+});
+
+timer('base64 - 1e4', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e4.toString('base64');
+});
+
+timer('ucs2 - 1e2', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e2.toString('ucs2');
+});
+
+timer('ucs2 - 1e4', function() {
+ for (var i = 0; i < LEN; i++)
+ buf1e4.toString('ucs2');
+});
View
49 benchmark/buffer_write.js → benchmark/buffer/buffer_write.js
@@ -1,4 +1,35 @@
-const LEN = 1e7;
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+/* Usage:
+ *
+ * --run: specify which test(s) to run
+ * --len: how many itterations each test should run (default: 1e7)
+ * --type: whether to use a 'fast' or 'slow' buffer (default: fast)
+ * --noassert: enable noAssert (default: false)
+ *
+ * Example:
+ *
+ * node buffer_write.js --run writeUInt8 --len 1e5 --type slow --noassert true
+ */
const INT8 = 0x7f;
const INT16 = 0x7fff;
@@ -7,16 +38,12 @@ const UINT8 = INT8 * 2;
const UINT16 = INT16 * 2;
const UINT32 = INT32 * 2;
-const noAssert = process.argv[3] == 'true' ? true
- : process.argv[3] == 'false' ? false
- : undefined;
-
-var timer = require('./_bench_timer');
-
-var buff = (process.argv[2] == 'slow') ?
- (new require('buffer').SlowBuffer(8)) :
- (new Buffer(8));
-var i;
+var timer = require('../_bench_timer');
+var parsed = timer.parse(process.argv);
+var Buff = parsed.type == 'slow' ? require('buffer').SlowBuffer : Buffer;
+var noAssert = parsed.noassert == 'true' ? true : false;
+var LEN = parsed.len || 1e6;
+var buff = Buff(8);
timer('writeUInt8', function() {
for (i = 0; i < LEN; i++) {
View
81 benchmark/buffer/buffer_write_string.js
@@ -0,0 +1,81 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+/* Usage:
+ *
+ * --run: specify which test(s) to run
+ * --len: how many itterations each test should run (default: 1e6)
+ * --type: whether to use a 'fast' or 'slow' buffer (default: fast)
+ *
+ * Example:
+ *
+ * node buffer_write_string.js --run 'write - 1e1' --len 1e5 --type slow
+ *
+ * Defaults are 'fast' and '1e6'.
+ */
+
+var timer = require('../_bench_timer');
+var parsed = timer.parse(process.argv);
+var Buff = parsed.type == 'slow' ? require('buffer').SlowBuffer : Buffer;
+var LEN = parsed.len || 1e6;
+var buff = Buff(1e4);
+var str1e1 = createString(1e1);
+var str1e2 = createString(1e2);
+var str1e3 = createString(1e3);
+
+timer('write - 1e1', function() {
+ for (var i = 0; i < LEN; i++)
+ buff.write(str1e1);
+});
+
+timer('write - 1e1@1e3', function() {
+ for (var i = 0; i < LEN; i++)
+ buff.write(str1e1, 1e3);
+});
+
+timer('write - 1e2', function() {
+ for (var i = 0; i < LEN; i++)
+ buff.write(str1e2);
+});
+
+timer('write - 1e2@1e3', function() {
+ for (var i = 0; i < LEN; i++)
+ buff.write(str1e2, 1e3);
+});
+
+timer('write - 1e3', function() {
+ for (var i = 0; i < LEN; i++)
+ buff.write(str1e3);
+});
+
+timer('write - 1e3@1e3', function() {
+ for (var i = 0; i < LEN; i++)
+ buff.write(str1e3, 1e3);
+});
+
+
+function createString(len) {
+ var str = 'a';
+ while (str.length * 2 <= len)
+ str += str;
+ str += str.substr(0, len - str.length);
+ return str;
+}
View
6 benchmark/buffer_creation.js
@@ -1,6 +0,0 @@
-SlowBuffer = require('buffer').SlowBuffer;
-
-for (var i = 0; i < 1e6; i++) {
- b = new SlowBuffer(10);
- b[1] = 2
-}
View
97 benchmark/buffer_read.js
@@ -1,97 +0,0 @@
-const LEN = 1e7;
-const noAssert = process.argv[3] == 'true' ? true
- : process.argv[3] == 'false' ? false
- : undefined;
-
-var timer = require('./_bench_timer');
-
-var buff = (process.argv[2] == 'slow') ?
- (new require('buffer').SlowBuffer(8)) :
- (new Buffer(8));
-var i;
-
-buff.writeDoubleLE(0, 0, noAssert);
-
-timer('readUInt8', function() {
- for (i = 0; i < LEN; i++) {
- buff.readUInt8(0, noAssert);
- }
-});
-
-timer('readUInt16LE', function() {
- for (i = 0; i < LEN; i++) {
- buff.readUInt16LE(0, noAssert);
- }
-});
-
-timer('readUInt16BE', function() {
- for (i = 0; i < LEN; i++) {
- buff.readUInt16BE(0, noAssert);
- }
-});
-
-timer('readUInt32LE', function() {
- for (i = 0; i < LEN; i++) {
- buff.readUInt32LE(0, noAssert);
- }
-});
-
-timer('readUInt32BE', function() {
- for (i = 0; i < LEN; i++) {
- buff.readUInt32BE(0, noAssert);
- }
-});
-
-timer('readInt8', function() {
- for (i = 0; i < LEN; i++) {
- buff.readInt8(0, noAssert);
- }
-});
-
-timer('readInt16LE', function() {
- for (i = 0; i < LEN; i++) {
- buff.readInt16LE(0, noAssert);
- }
-});
-
-timer('readInt16BE', function() {
- for (i = 0; i < LEN; i++) {
- buff.readInt16BE(0, noAssert);
- }
-});
-
-timer('readInt32LE', function() {
- for (i = 0; i < LEN; i++) {
- buff.readInt32LE(0, noAssert);
- }
-});
-
-timer('readInt32BE', function() {
- for (i = 0; i < LEN; i++) {
- buff.readInt32BE(0, noAssert);
- }
-});
-
-timer('readFloatLE', function() {
- for (i = 0; i < LEN; i++) {
- buff.readFloatLE(0, noAssert);
- }
-});
-
-timer('readFloatBE', function() {
- for (i = 0; i < LEN; i++) {
- buff.readFloatBE(0, noAssert);
- }
-});
-
-timer('readDoubleLE', function() {
- for (i = 0; i < LEN; i++) {
- buff.readDoubleLE(0, noAssert);
- }
-});
-
-timer('readDoubleBE', function() {
- for (i = 0; i < LEN; i++) {
- buff.readDoubleBE(0, noAssert);
- }
-});
View
27 benchmark/buffer-base64-encode.js → benchmark/events/events_creation.js
@@ -19,9 +19,24 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-var N = 64*1024*1024
-var b = Buffer(N);
-var s = '';
-for (var i = 0; i < 256; ++i) s += String.fromCharCode(i);
-for (var i = 0; i < N; i += 256) b.write(s, i, 256, 'ascii');
-for (var i = 0; i < 32; ++i) b.toString('base64');
+/* Usage:
+ *
+ * --run: specify which test(s) to run
+ * --len: how many itterations each test should run (default: 1e6)
+ *
+ * Example:
+ *
+ * node events_creations.js --run 'create' --len 1e5
+ */
+
+var EventEmitter = require('events').EventEmitter;
+var timer = require('../_bench_timer');
+var parsed = timer.parse(process.argv);
+var LEN = parsed.len || 1e6;
+
+(function() {
+ timer('create', function() {
+ for (var i = 0; i < LEN; i++)
+ new EventEmitter();
+ });
+}());
View
94 benchmark/events/events_emit.js
@@ -0,0 +1,94 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+/* Usage:
+ *
+ * --run: specify which test(s) to run
+ * --len: how many itterations each test should run (default: 1e6)
+ *
+ * Example:
+ *
+ * node events_emit.js --run 'emit - 1 arg' --len 1e5
+ */
+
+var EventEmitter = require('events').EventEmitter;
+var timer = require('../_bench_timer');
+var parsed = timer.parse(process.argv);
+var LEN = parsed.len || 1e6;
+
+(function() {
+ var emitter = new EventEmitter();
+ emitter.on('test', function(msg) { });
+ timer('emit - 1 arg 1 listener', function() {
+ for (var i = 0; i < LEN; i++)
+ emitter.emit('test', 'message');
+ });
+}());
+
+(function() {
+ var emitter = new EventEmitter();
+ for (var i = 0; i < 10; i++)
+ emitter.on('test', function(msg) { });
+ timer('emit - 1 arg 10 listeners', function() {
+ for (var i = 0; i < LEN; i++)
+ emitter.emit('test', 'message');
+ });
+}());
+
+(function() {
+ var emitter = new EventEmitter();
+ emitter.setMaxListeners(100);
+ for (var i = 0; i < 100; i++)
+ emitter.on('test', function(msg) { });
+ timer('emit - 1 arg 100 listeners', function() {
+ for (var i = 0; i < LEN; i++)
+ emitter.emit('test', 'message');
+ });
+}());
+
+(function() {
+ var emitter = new EventEmitter();
+ emitter.on('test', function(a,b,c,d,e) { });
+ timer('emit - 5 arg 1 listener', function() {
+ for (var i = 0; i < LEN; i++)
+ emitter.emit('test','a','b','c','d','e');
+ });
+}());
+
+(function() {
+ var emitter = new EventEmitter();
+ for (var i = 0; i < 10; i++)
+ emitter.on('test', function(a,b,c,d,e) { });
+ timer('emit - 5 arg 10 listeners', function() {
+ for (var i = 0; i < LEN; i++)
+ emitter.emit('test','a','b','c','d','e');
+ });
+}());
+
+(function() {
+ var emitter = new EventEmitter();
+ emitter.on('newListener', function() { });
+ emitter.on('test', function(a) { });
+ timer('emit - 1 newListener', function() {
+ for (var i = 0; i < LEN; i++)
+ emitter.emit('test','a');
+ });
+}());
View
79 benchmark/events/events_listeners.js
@@ -0,0 +1,79 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+/* Usage:
+ *
+ * --run: specify which test(s) to run
+ * --len: how many itterations each test should run (default: 1e6)
+ *
+ * Example:
+ *
+ * node events_listeners.js --run 'add names' --len 1e5
+ */
+
+var EventEmitter = require('events').EventEmitter;
+var timer = require('../_bench_timer');
+var parsed = timer.parse(process.argv);
+var LEN = parsed.len || 1e6;
+
+(function() {
+ var emitter = new EventEmitter();
+ emitter.setMaxListeners(0);
+ timer('add names', function() {
+ for (var i = 0; i < LEN; i++) {
+ emitter.on('i', function() { });
+ }
+ });
+}());
+
+(function() {
+ var emitter = new EventEmitter();
+ var fn;
+ timer('add remove', function() {
+ for (var i = 0; i < LEN; i++) {
+ fn = function() { };
+ emitter.on('test', fn);
+ emitter.removeListener('test', fn);
+ }
+ });
+}());
+
+(function() {
+ var emitter = new EventEmitter();
+ var fn = function() { };
+ timer('add removeAll', function() {
+ for (var i = 0; i < LEN; i++) {
+ emitter.on('test', fn);
+ emitter.removeAllListeners('test');
+ }
+ });
+}());
+
+(function() {
+ var emitter = new EventEmitter();
+ for (var i = 0; i < 10; i++)
+ emitter.on('test', function() { });
+ timer('listeners - 10', function() {
+ for (var i = 0; i < LEN; i++) {
+ emitter.listeners('test');
+ }
+ });
+}());
View
42 benchmark/fast_buffer2.js
@@ -1,42 +0,0 @@
-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++
View
6 benchmark/fast_buffer2_creation.js
@@ -1,6 +0,0 @@
-
-FastBuffer = require('./fast_buffer2').FastBuffer;
-for (var i = 0; i < 1e6; i++) {
- b = new FastBuffer(10);
- b[1] = 2;
-}
View
4 benchmark/fast_buffer_creation.js
@@ -1,4 +0,0 @@
-for (var i = 0; i < 1e6; i++) {
- b = new Buffer(10);
- b[1] = 2;
-}
View
42 benchmark/http/http_trivial.js
@@ -0,0 +1,42 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+/* Usage:
+ *
+ * Right now there are no usage parameters. This is run by http_trivial.sh.
+ *
+ */
+
+var http = require('http');
+var timer = require('../_bench_timer');
+
+timer('httpTrivial', 1000);
+http.createServer(function(req, res) {
+ timer.inc('httpTrivial');
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.end('Hello World\n');
+}).listen(8000);
+
+console.log('pid ' + process.pid);
+console.log('Listening at http://127.0.0.1:8000/');
+process.on('exit', function() {
+ console.error('libuv counter', process.uvCounters());
+});
View
15 benchmark/http/http_trivial.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+cd "$(dirname "$(dirname $0)")"
+
+node=${NODE:-../node}
+
+$node http/http_trivial.js &
+npid=$!
+
+sleep 1
+
+for i in a a a a a a a a a a a a a a a a a a a a; do
+ ab -t 10 -c 100 http://127.0.0.1:8000/ > /dev/null 2>&1
+done
+
+kill $npid
View
0 benchmark/dataview_set.js → benchmark/typedarray/dataview_set.js
File renamed without changes.
View
3 benchmark/arrays/var_int.js → benchmark/typedarray/var_int.js
@@ -1,4 +1,5 @@
-var types = 'Array Buffer Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split(' ');
+var types = ('Array Buffer Int8Array Uint8Array Int16Array Uint16Array' +
+ 'Int32Array Uint32Array Float32Array Float64Array').split(' ');
var type = types[types.indexOf(process.argv[2])];
if (!type)
View
3 benchmark/arrays/zero_float.js → benchmark/typedarray/zero_float.js
@@ -1,4 +1,5 @@
-var types = 'Array Buffer Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split(' ');
+var types = ('Array Buffer Int8Array Uint8Array Int16Array Uint16Array' +
+ 'Int32Array Uint32Array Float32Array Float64Array').split(' ');
var type = types[types.indexOf(process.argv[2])];
if (!type)
View
3 benchmark/arrays/zero_int.js → benchmark/typedarray/zero_int.js
@@ -1,4 +1,5 @@
-var types = 'Array Buffer Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split(' ');
+var types = ('Array Buffer Int8Array Uint8Array Int16Array Uint16Array' +
+ 'Int32Array Uint32Array Float32Array Float64Array').split(' ');
var type = types[types.indexOf(process.argv[2])];
if (!type)

0 comments on commit d41302f

Please sign in to comment.