Skip to content

Commit

Permalink
Added benchmarks utilizing apache bench
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed May 31, 2010
1 parent 9032c6d commit 142dc02
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
results
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ TESTS ?= test/*.test.js
test:
@CONNECT_CWD=test/fixtures/app ./$(TEST) -I lib $(TESTS)

.PHONY: test test-debug
benchmark: benchmarks/run
@./benchmarks/run

.PHONY: test test-debug benchmark
19 changes: 19 additions & 0 deletions benchmarks/hello-world/connect.buffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

/**
* Module dependencies.
*/

var Buffer = require('buffer').Buffer,
body = new Buffer('Hello World', 'ascii');

require('../../lib/connect').createServer([
{ module: {
handle: function(err, req, res, next){
res.writeHead(200, {
'Content-Type': 'text/plain',
'Content-Length': body.length
});
res.end(body);
}
}}
]).listen(3000);
16 changes: 16 additions & 0 deletions benchmarks/hello-world/node.buffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

/**
* Module dependencies.
*/

var http = require('http'),
Buffer = require('buffer').Buffer,
body = new Buffer('Hello World', 'ascii');

http.createServer(function(req, res){
res.writeHead(200, {
'Content-Type': 'text/plain',
'Content-Length': body.length
});
res.end(body);
}).listen(3000);
15 changes: 15 additions & 0 deletions benchmarks/hello-world/node.string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

/**
* Module dependencies.
*/

var http = require('http'),
body = 'Hello World';

http.createServer(function(req, res){
res.writeHead(200, {
'Content-Type': 'text/plain',
'Content-Length': body.length
});
res.end(body);
}).listen(3000);
36 changes: 34 additions & 2 deletions benchmarks/run
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

SLEEP=${SLEEP-2}
ABFLAGS=${ABFLAGS-"-m 2000 -c 50 -k"}
ADDR=${ADDR-http://localhost:3000}
ABFLAGS=${ABFLAGS-"-n 2000 -c 50 -k"}
ADDR=${ADDR-http://0.0.0.0:3000/}
AB=${AB-ab}

#
Expand All @@ -14,3 +14,35 @@ AB=${AB-ab}
log(){
echo "... $@"
}

#
# Benchmark the given <dir>.
#
# <dir>
#

bm(){
local dir=$1;
for file in benchmarks/$dir/*; do
log running $file
case $file in
*.js)
node $file &
;;
esac
local pid=$!
sleep $SLEEP
local dirname=results/$(dirname $file)
mkdir -p $dirname
$AB $ABFLAGS -g results/$file.dat $ADDR > results/$file.out
log $(cat results/$file.out | grep Requests)
kill -9 $pid
done
}

# Make ./results
mkdir -p results

# Run benchmarks
log $AB $ABFLAGS $ADDR
bm hello-world

0 comments on commit 142dc02

Please sign in to comment.