Skip to content

Instantly share code, notes, and snippets.

@jed
Created June 12, 2010 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jed/435548 to your computer and use it in GitHub Desktop.
Save jed/435548 to your computer and use it in GitHub Desktop.
var body = "Hello World"
, http = require( "http" )
, puts = require( "sys" ).puts
, connect = require( "./Connect/lib/connect" )
, jsgiNode = require( "./jsgi-node" )
, fab = require( "fab_old" )
, connectMiddleware = {
handle: function(req, res, next){
next();
}
}
, connectApp = {
handle: function(req, res){
res.writeHead(200, {});
res.end(body);
}
}
, JSGIMiddleware = function(next) {
return function(request) {
return next(request);
}
}
, JSGIApp = function() {
return {
status:200,
body:[ body ],
headers:{}
}
}
, fabMiddleware = function( app ) {
return function() {
return app.call( this );
}
}
, fabApp = function() {
this({ status: 200, body: body })();
}
, clients =
{ connect: http.createClient( 8000 )
, JSGI: http.createClient( 8001 )
, fab: http.createClient( 8002 )
}
connect.createServer([
{ module: connectMiddleware },
{ module: connectMiddleware },
{ module: connectMiddleware },
{ module: connectMiddleware },
{ module: connectMiddleware },
{ module: connectMiddleware },
{ module: connectMiddleware },
{ module: connectMiddleware },
{ module: connectMiddleware },
{ module: connectApp }
]).listen( 8000 );
http.createServer(
jsgiNode.Listener(
JSGIMiddleware(
JSGIMiddleware(
JSGIMiddleware(
JSGIMiddleware(
JSGIMiddleware(
JSGIMiddleware(
JSGIMiddleware(
JSGIMiddleware(
JSGIMiddleware(
JSGIApp
)
)
)
)
)
)
)
)
)
)
).listen( 8001 );
( fab )
( fab.listen, 8002 )
( fabMiddleware )
( fabMiddleware )
( fabMiddleware )
( fabMiddleware )
( fabMiddleware )
( fabMiddleware )
( fabMiddleware )
( fabMiddleware )
( fabMiddleware )
( fabApp );
function test( name, cb ) {
var client = clients[ name ]
, start = +new Date
, remaining = 1000;
( function loop() {
if ( remaining-- ) {
client
.request( "GET", "/" )
.addListener( "response", function( response ) {
response.addListener( "end", loop )
})
.end();
}
else {
puts( name + " took " + ( +new Date - start ) + "ms" )
cb();
}
})();
}
test( "connect", function() {
test( "JSGI", function() {
test( "fab", function(){} )
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment