Last active
December 12, 2015 07:49
-
-
Save isaacs/4739818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the file in benchmark/http/http_simple.js | |
var common = require('../common.js'); | |
var PORT = common.PORT; | |
var bench = common.createBenchmark(main, { | |
// unicode confuses ab on os x. | |
type: ['bytes', 'buffer'], | |
length: [4, 1024, 102400], | |
c: [50, 150] | |
}); | |
function main(conf) { | |
process.env.PORT = PORT; | |
var spawn = require('child_process').spawn; | |
var simple = require('path').resolve(__dirname, '../http_simple.js'); | |
var server = spawn(process.execPath, [simple]); | |
setTimeout(function() { | |
var path = '/' + conf.type + '/' + conf.length; //+ '/' + conf.chunks; | |
var args = ['-r', '-t', 5]; | |
if (+conf.c !== 1) | |
args.push('-c', conf.c); | |
args.push('-k'); | |
bench.ab(path, args, function() { | |
server.kill(); | |
}); | |
}, 2000); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#� Relevant bit of the Makefile | |
bench-net: all | |
@$(NODE) benchmark/common.js net | |
bench-http: all | |
@$(NODE) benchmark/common.js http | |
bench-misc: all | |
@$(NODE) benchmark/common.js misc | |
bench: bench-misc bench-net bench-http |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test the speed of .pipe() with sockets | |
var common = require('../common.js'); | |
var PORT = common.PORT; | |
var bench = common.createBenchmark(main, { | |
len: [102400, 1024 * 1024 * 16], | |
type: ['utf', 'asc', 'buf'], | |
dur: [1, 3], | |
}); | |
var dur; | |
var len; | |
var type; | |
var chunk; | |
var encoding; | |
function main(conf) { | |
dur = +conf.dur; | |
len = +conf.len; | |
type = conf.type; | |
switch (type) { | |
case 'buf': | |
chunk = new Buffer(len); | |
chunk.fill('x'); | |
break; | |
case 'utf': | |
encoding = 'utf8'; | |
chunk = new Array(len / 2 + 1).join('ü'); | |
break; | |
case 'asc': | |
encoding = 'ascii'; | |
chunk = new Array(len + 1).join('x'); | |
break; | |
default: | |
throw new Error('invalid type: ' + type); | |
break; | |
} | |
server(); | |
} | |
var net = require('net'); | |
function Writer() { | |
this.received = 0; | |
this.writable = true; | |
} | |
Writer.prototype.write = function(chunk, encoding, cb) { | |
this.received += chunk.length; | |
if (typeof encoding === 'function') | |
encoding(); | |
else if (typeof cb === 'function') | |
cb(); | |
return true; | |
}; | |
// doesn't matter, never emits anything. | |
Writer.prototype.on = function() {}; | |
Writer.prototype.once = function() {}; | |
Writer.prototype.emit = function() {}; | |
function Reader() { | |
this.flow = this.flow.bind(this); | |
this.readable = true; | |
} | |
Reader.prototype.pipe = function(dest) { | |
this.dest = dest; | |
this.flow(); | |
return dest; | |
}; | |
Reader.prototype.flow = function() { | |
var dest = this.dest; | |
var res = dest.write(chunk, encoding); | |
if (!res) | |
dest.once('drain', this.flow); | |
else | |
process.nextTick(this.flow); | |
}; | |
function server() { | |
var reader = new Reader(); | |
var writer = new Writer(); | |
// the actual benchmark. | |
var server = net.createServer(function(socket) { | |
socket.pipe(socket); | |
}); | |
server.listen(PORT, function() { | |
var socket = net.connect(PORT); | |
socket.on('connect', function() { | |
bench.start(); | |
reader.pipe(socket); | |
socket.pipe(writer); | |
setTimeout(function() { | |
// multiply by 2 since we're sending it first one way | |
// then then back again. | |
var bytes = writer.received * 2; | |
var gbits = (bytes * 8) / (1024 * 1024 * 1024); | |
bench.end(gbits); | |
}, dur * 1000); | |
}); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
misc/url.js parse(): 14456 | |
misc/url.js format(): 13940 | |
misc/url.js resolve("../foo/bar?baz=boom"): 5946.7 | |
misc/url.js resolve("foo/bar"): 6287.2 | |
misc/url.js resolve("http://nodejs.org"): 5637.3 | |
misc/url.js resolve("./foo/bar?baz"): 6003.3 | |
net/net-c2s.js len=102400 type=utf dur=1: 2.3901 | |
net/net-c2s.js len=102400 type=utf dur=3: 2.4302 | |
net/net-c2s.js len=102400 type=asc dur=1: 3.3265 | |
net/net-c2s.js len=102400 type=asc dur=3: 3.4387 | |
net/net-c2s.js len=102400 type=buf dur=1: 4.9464 | |
net/net-c2s.js len=102400 type=buf dur=3: 4.9651 | |
net/net-c2s.js len=16777216 type=utf dur=1: 1.7060 | |
net/net-c2s.js len=16777216 type=utf dur=3: 1.7999 | |
net/net-c2s.js len=16777216 type=asc dur=1: 3.0969 | |
net/net-c2s.js len=16777216 type=asc dur=3: 3.0895 | |
net/net-c2s.js len=16777216 type=buf dur=1: 5.9019 | |
net/net-c2s.js len=16777216 type=buf dur=3: 5.9814 | |
net/net-pipe.js len=102400 type=utf dur=1: 3.2214 | |
net/net-pipe.js len=102400 type=utf dur=3: 3.2842 | |
net/net-pipe.js len=102400 type=asc dur=1: 4.1186 | |
net/net-pipe.js len=102400 type=asc dur=3: 4.1770 | |
net/net-pipe.js len=102400 type=buf dur=1: 5.1369 | |
net/net-pipe.js len=102400 type=buf dur=3: 5.2137 | |
net/net-pipe.js len=16777216 type=utf dur=1: 2.5733 | |
net/net-pipe.js len=16777216 type=utf dur=3: 2.6532 | |
net/net-pipe.js len=16777216 type=asc dur=1: 3.6920 | |
net/net-pipe.js len=16777216 type=asc dur=3: 3.7991 | |
net/net-pipe.js len=16777216 type=buf dur=1: 5.7940 | |
net/net-pipe.js len=16777216 type=buf dur=3: 5.6903 | |
net/net-s2c.js len=102400 type=utf dur=1: 2.4032 | |
net/net-s2c.js len=102400 type=utf dur=3: 2.4213 | |
net/net-s2c.js len=102400 type=asc dur=1: 3.3259 | |
net/net-s2c.js len=102400 type=asc dur=3: 3.4714 | |
net/net-s2c.js len=102400 type=buf dur=1: 4.9941 | |
net/net-s2c.js len=102400 type=buf dur=3: 5.0931 | |
net/net-s2c.js len=16777216 type=utf dur=1: 1.8200 | |
net/net-s2c.js len=16777216 type=utf dur=3: 1.8258 | |
net/net-s2c.js len=16777216 type=asc dur=1: 3.1436 | |
net/net-s2c.js len=16777216 type=asc dur=3: 3.1344 | |
net/net-s2c.js len=16777216 type=buf dur=1: 5.8372 | |
net/net-s2c.js len=16777216 type=buf dur=3: 5.9162 | |
net/tcp-raw-c2s.js len=102400 type=utf dur=1: 2.6764 | |
net/tcp-raw-c2s.js len=102400 type=utf dur=3: 2.5873 | |
net/tcp-raw-c2s.js len=102400 type=asc dur=1: 3.8176 | |
net/tcp-raw-c2s.js len=102400 type=asc dur=3: 3.8030 | |
net/tcp-raw-c2s.js len=102400 type=buf dur=1: 6.0361 | |
net/tcp-raw-c2s.js len=102400 type=buf dur=3: 6.2023 | |
net/tcp-raw-c2s.js len=16777216 type=utf dur=1: 1.8609 | |
net/tcp-raw-c2s.js len=16777216 type=utf dur=3: 1.8960 | |
net/tcp-raw-c2s.js len=16777216 type=asc dur=1: 3.3395 | |
net/tcp-raw-c2s.js len=16777216 type=asc dur=3: 3.3197 | |
net/tcp-raw-c2s.js len=16777216 type=buf dur=1: 6.2086 | |
net/tcp-raw-c2s.js len=16777216 type=buf dur=3: 6.1883 | |
net/tcp-raw-pipe.js len=102400 type=utf dur=1: 3.7425 | |
net/tcp-raw-pipe.js len=102400 type=utf dur=3: 3.6587 | |
net/tcp-raw-pipe.js len=102400 type=asc dur=1: 4.7078 | |
net/tcp-raw-pipe.js len=102400 type=asc dur=3: 4.6811 | |
net/tcp-raw-pipe.js len=102400 type=buf dur=1: 4.7906 | |
net/tcp-raw-pipe.js len=102400 type=buf dur=3: 5.8061 | |
net/tcp-raw-pipe.js len=16777216 type=utf dur=1: 2.0117 | |
net/tcp-raw-pipe.js len=16777216 type=utf dur=3: 2.5120 | |
net/tcp-raw-pipe.js len=16777216 type=asc dur=1: 3.8303 | |
net/tcp-raw-pipe.js len=16777216 type=asc dur=3: 3.8421 | |
net/tcp-raw-pipe.js len=16777216 type=buf dur=1: 5.6981 | |
net/tcp-raw-pipe.js len=16777216 type=buf dur=3: 5.6583 | |
net/tcp-raw-s2c.js len=102400 type=utf dur=1: 2.6373 | |
net/tcp-raw-s2c.js len=102400 type=utf dur=3: 2.5934 | |
net/tcp-raw-s2c.js len=102400 type=asc dur=1: 3.7769 | |
net/tcp-raw-s2c.js len=102400 type=asc dur=3: 3.7522 | |
net/tcp-raw-s2c.js len=102400 type=buf dur=1: 5.9772 | |
net/tcp-raw-s2c.js len=102400 type=buf dur=3: 6.1143 | |
net/tcp-raw-s2c.js len=16777216 type=utf dur=1: 1.7094 | |
net/tcp-raw-s2c.js len=16777216 type=utf dur=3: 1.9018 | |
net/tcp-raw-s2c.js len=16777216 type=asc dur=1: 3.3770 | |
net/tcp-raw-s2c.js len=16777216 type=asc dur=3: 3.3220 | |
net/tcp-raw-s2c.js len=16777216 type=buf dur=1: 6.0739 | |
net/tcp-raw-s2c.js len=16777216 type=buf dur=3: 6.1751 | |
http/cluster.js type=bytes length=4 c=50: 19189 | |
http/cluster.js type=bytes length=4 c=150: 18932 | |
http/cluster.js type=bytes length=1024 c=50: 17492 | |
http/cluster.js type=bytes length=1024 c=150: 17385 | |
http/cluster.js type=bytes length=102400 c=50: 1522.4 | |
http/cluster.js type=bytes length=102400 c=150: 1502.6 | |
http/cluster.js type=buffer length=4 c=50: 17784 | |
http/cluster.js type=buffer length=4 c=150: 17550 | |
http/cluster.js type=buffer length=1024 c=50: 17512 | |
http/cluster.js type=buffer length=1024 c=150: 17197 | |
http/cluster.js type=buffer length=102400 c=50: 7951.3 | |
http/cluster.js type=buffer length=102400 c=150: 8318.0 | |
http/http_simple.js type=bytes length=4 c=50: 12220 | |
http/http_simple.js type=bytes length=4 c=150: 11848 | |
http/http_simple.js type=bytes length=1024 c=50: 11004 | |
http/http_simple.js type=bytes length=1024 c=150: 10724 | |
http/http_simple.js type=bytes length=102400 c=50: 902.89 | |
http/http_simple.js type=bytes length=102400 c=150: 881.05 | |
http/http_simple.js type=buffer length=4 c=50: 11382 | |
http/http_simple.js type=buffer length=4 c=150: 11393 | |
http/http_simple.js type=buffer length=1024 c=50: 11256 | |
http/http_simple.js type=buffer length=1024 c=150: 10853 | |
http/http_simple.js type=buffer length=102400 c=50: 5438.1 | |
http/http_simple.js type=buffer length=102400 c=150: 5380.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment