Permalink
Browse files

use benchmarx

  • Loading branch information...
1 parent eeb82f6 commit 8c33d7ba5231ae6a307c179df6c996b698aee425 Carlos Rodriguez committed Aug 29, 2012
View
@@ -4,7 +4,7 @@ test:
--bail \
--require test/common.js
-bench: install-bench bench-middleware bench-routes
+bench: install-bench bench-middleware bench-routing
check = \
if [ -z `which siege` ]; then \
@@ -17,30 +17,17 @@ install-bench:
@npm install
@cd bench; npm install
-bench-middleware:
- @echo "middleware\n==========" && echo
+bench-middleware: install-bench
+ @./node_modules/.bin/benchmarx \
+ --title "middleware" \
+ --runner siege \
+ bench/middleware/*.js
- @echo "middler\n-------"
- @sleep 10
- @cd bench; ./bench.js middler && echo
- @echo "union\n-----"
- @sleep 10
- @cd bench; ./bench.js union && echo
- @echo "connect\n-------"
- @sleep 10
- @cd bench; ./bench.js connect && echo
+bench-routing: install-bench
+ @./node_modules/.bin/benchmarx \
+ --title "routing" \
+ --runner siege \
+ --path bench/paths.txt \
+ bench/routing/*.js
-bench-routes:
- @echo "routes\n======" && echo
-
- @echo "middler\n-------"
- @sleep 10
- @cd bench; ./bench.js middler-routes && echo
- @echo "director\n--------"
- @sleep 10
- @cd bench; ./bench.js director-routes && echo
- @echo "express\n-------"
- @sleep 10
- @cd bench; ./bench.js express-routes && echo
-
-.PHONY: test bench
+.PHONY: test bench
View
@@ -119,7 +119,15 @@ middler(server)
Benchmarks
----------
-See [here](https://github.com/carlos8f/node-middler/tree/master/bench)
+In the middler root, run:
+
+```bash
+$ make bench
+```
+
+Brought to you by [benchmarx](https://github.com/carlos8f/node-benchmarx).
+
+My results: https://gist.github.com/3473117
License
-------
View
@@ -1,48 +0,0 @@
-#!/usr/bin/env node
-
-var spawn = require('child_process').spawn
- , test = process.argv[2]
- , fs = require('fs')
- , idgen = require('idgen')
-
-var testServer = spawn('node', [require('path').resolve(__dirname, './' + test)]);
-testServer.stdout.once('data', function (chunk) {
- var port = parseInt(chunk, 10)
- , id = idgen()
- , baseUrl = 'http://localhost:' + port
- , logFilePath = '/tmp/middler-benchmark-' + id + '.log'
- , args = ['-b', '-t', '30s', '--log=' + logFilePath]
-
- if (test.indexOf('routes') !== -1) {
- var urls = []
- , urlFilePath = '/tmp/middler-benchmark-' + id + '.txt'
-
- for (var i = 1; i <= 100; i++) {
- urls.push(baseUrl + '/test/' + i);
- }
- // Repeat all the urls, in case there is caching.
- urls = urls.concat(urls);
-
- fs.writeFileSync(urlFilePath, urls.join('\n'));
- args = args.concat(['-f', urlFilePath]);
- }
- else {
- args.push(baseUrl + '/');
- }
- var siege = spawn('siege', args)
- , output = ''
-
- siege.stderr.on('data', function (chunk) {
- output += chunk;
- });
-
- siege.on('close', function () {
- console.log(output);
- // console.log(output.match(/([\d\.]+ trans\/sec)/)[1]);
- fs.unlinkSync(logFilePath);
- if (typeof urlFilePath !== 'undefined') {
- fs.unlinkSync(urlFilePath);
- }
- testServer.kill();
- });
-});
View
@@ -1,13 +0,0 @@
-var connect = require('connect')
- , http = require('http')
-
-var app = connect();
-
-app.use(function (req, res, next) {
- res.end('hello world');
-});
-
-var server = http.createServer(app);
-
-server.listen(0);
-console.log(server.address().port);
View
@@ -1,24 +0,0 @@
-var union = require('union')
- , director = require('director')
-
-var router = new director.http.Router();
-
-var server = union.createServer({
- before: [
- function (req, res) {
- var found = router.dispatch(req, res);
- if (!found) {
- res.emit('next');
- }
- }
- ]
-});
-
-for (var i = 1; i <= 100; i++) {
- router.get('/test/' + i, function () {
- this.res.end('test #' + i);
- });
-}
-
-server.listen(0);
-console.log(server.address().port);
View
@@ -1,20 +0,0 @@
-var express = require('express')
- , http = require('http')
- , path = require('path');
-
-var app = express();
-
-app.configure(function(){
- app.use(app.router);
-});
-
-for (var i = 1; i <= 100; i++) {
- app.get('/test/' + i, function (req, res, next) {
- res.end('test #' + i);
- });
-}
-
-var server = http.createServer(app);
-
-server.listen(0);
-console.log(server.address().port);
View
@@ -1,13 +0,0 @@
-var middler = require('../')()
- , server = require('http').createServer()
-
-for (var i = 1; i <= 100; i++) {
- middler.get('/test/' + i, function (req, res, next) {
- res.end('test #' + i);
- });
-}
-
-middler.attach(server);
-
-server.listen(0);
-console.log(server.address().port);
View
@@ -1,11 +0,0 @@
-var middler = require('../')()
- , server = require('http').createServer()
-
-middler
- .add(function (req, res, next) {
- res.end('hello world');
- })
- .attach(server);
-
-server.listen(0);
-console.log(server.address().port);
@@ -0,0 +1,20 @@
+var connect = require('connect')
+ , http = require('http')
+ , server
+
+exports.listen = function (options, cb) {
+ var app = connect();
+
+ app.use(function (req, res, next) {
+ res.end('hello world');
+ });
+
+ server = http.createServer(app);
+ server.listen(0, function () {
+ cb(null, server.address().port);
+ });
+};
+
+exports.close = function () {
+ server.close();
+};
@@ -0,0 +1,23 @@
+var middler = require('../../')()
+ , http = require('http')
+ , server
+
+exports.version = require(require('path').resolve(__dirname, '../../package')).version;
+
+exports.listen = function (options, cb) {
+ server = http.createServer();
+
+ middler
+ .add(function (req, res, next) {
+ res.end('hello world');
+ })
+ .attach(server);
+
+ server.listen(0, function () {
+ cb(null, server.address().port);
+ });
+};
+
+exports.close = function () {
+ server.close();
+};
View
@@ -0,0 +1,20 @@
+var union = require('union')
+ , server
+
+exports.listen = function (options, cb) {
+ server = union.createServer({
+ before: [
+ function (req, res) {
+ res.end('hello world');
+ }
+ ]
+ });
+
+ server.listen(0, function () {
+ cb(null, server.address().port);
+ });
+};
+
+exports.close = function () {
+ server.close();
+};
View
@@ -5,7 +5,6 @@
"express": "~3.0.0rc3",
"director": "~1.1.3",
"union": "~0.3.4",
- "connect": "~2.4.3",
- "idgen": "~1.1.1"
+ "connect": "~2.4.3"
}
-}
+}
View
@@ -0,0 +1,100 @@
+/test/1
+/test/2
+/test/3
+/test/4
+/test/5
+/test/6
+/test/7
+/test/8
+/test/9
+/test/10
+/test/11
+/test/12
+/test/13
+/test/14
+/test/15
+/test/16
+/test/17
+/test/18
+/test/19
+/test/20
+/test/21
+/test/22
+/test/23
+/test/24
+/test/25
+/test/26
+/test/27
+/test/28
+/test/29
+/test/30
+/test/31
+/test/32
+/test/33
+/test/34
+/test/35
+/test/36
+/test/37
+/test/38
+/test/39
+/test/40
+/test/41
+/test/42
+/test/43
+/test/44
+/test/45
+/test/46
+/test/47
+/test/48
+/test/49
+/test/50
+/test/51
+/test/52
+/test/53
+/test/54
+/test/55
+/test/56
+/test/57
+/test/58
+/test/59
+/test/60
+/test/61
+/test/62
+/test/63
+/test/64
+/test/65
+/test/66
+/test/67
+/test/68
+/test/69
+/test/70
+/test/71
+/test/72
+/test/73
+/test/74
+/test/75
+/test/76
+/test/77
+/test/78
+/test/79
+/test/80
+/test/81
+/test/82
+/test/83
+/test/84
+/test/85
+/test/86
+/test/87
+/test/88
+/test/89
+/test/90
+/test/91
+/test/92
+/test/93
+/test/94
+/test/95
+/test/96
+/test/97
+/test/98
+/test/99
+/test/100
Oops, something went wrong.

0 comments on commit 8c33d7b

Please sign in to comment.