Skip to content
This repository has been archived by the owner on Jan 15, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:jmervine/bench
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Mervine committed Sep 20, 2015
2 parents 5669c71 + 6dae35c commit fa8f15a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
var spawn = require('child_process').spawn;
var path = require('path');
var async = require('async');

var Bench = require('./lib/bench');
var cli = require('./lib/cli');

var db = require('mongojs')(cli.database, [cli.collection]);

var bench = new Bench(cli.url);
var runs = [];
var runcount = 0;
var db;

function median(values) {
values.sort(function(a,b) {return (a.last_nom > b.last_nom) ? 1 : ((b.last_nom > a.last_nom) ? -1 : 0);} );
values.sort(function(a,b) { return a.metrics.httpTrafficCompleted - b.metrics.httpTrafficCompleted;} );
var half = Math.floor(values.length/2);
if (values.length % 2) {
return values[half];
}
return (values[half-1] + values[half]) / 2.0;
var ret=values[half];
var other=values[half-1].metrics;
for(i in ret.metrics ){
ret.metrics[i]=(ret.metrics[i]+other[i])/2;
}
return ret;
}

function seriesAction(callback) {
Expand Down Expand Up @@ -71,9 +73,8 @@ switch (cli.action) {
for (i = 0; i < cli.runs; i++) {
series.push(seriesAction);
}

before();
async.series(series, function (err, result) {
async.parallelLimit(series,cli.limit, function (err, result) {
var set = median(runs);
set.created_at = Date.now();
if (set) {
Expand All @@ -95,4 +96,3 @@ switch (cli.action) {
}
});
}

11 changes: 6 additions & 5 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ var path = require('path');
cli
.version('0.0.1')
.usage('[options] [url]')
.option('-d , --database [DATBASE]' , 'mongodb connection string')
.option('-t , --collection [COLLECTION]' , 'mongodb collection name (default: client)')
.option('-r , --runs [RUNS]' , '[BENCH ONLY] number of runs (defult: 9)' , parseInt)
.option('-c , --config [CONFIG]' , 'config file location');
.option('-d , --database [DATABASE]' , 'mongodb connection string')
.option('-t , --collection [COLLECTION]' , 'mongodb collection name (default: client)')
.option('-r , --runs [RUNS]' , '[BENCH ONLY] number of runs (default: 9)' , parseInt)
.option('-l , --limit [RUNS]' , '[BENCH ONLY] number of runs (default: cpus + 1)' , parseInt)
.option('-c , --config [CONFIG]' , 'config file location');

cli
.command('server')
Expand Down Expand Up @@ -39,8 +40,8 @@ if (!cli.url) {
}

cli.action = cli.action || 'bench';

cli.runs = cli.runs || 9;
cli.limit = cli.limit || require('os').cpus().length + 1;
cli.database = cli.database || 'localhost/benchdb';
cli.collection = cli.collection || 'client';

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bench",
"version": "0.1.0",
"version": "0.1.1",
"description": "Benchmark a web page and display results with a pretty UI.",
"main": "index.js",
"scripts": {
Expand All @@ -24,6 +24,7 @@
"performance"
],
"author": "Joshua Mervine <[email protected]> (http://mervine.net)",
"contributors": ["Nicholas Jones <[email protected]> (http://nich.olas.biz)"],
"license": "BSD",
"bugs": {
"url": "https://github.com/jmervine/bench/issues"
Expand All @@ -36,7 +37,7 @@
"jade": ">= 0.0.1",
"connect": "~2.8.5",
"async": "~0.2.9",
"mongojs": "~0.7.17"
"mongojs": "0.10.*"
},
"devDependencies": {
"nodeunit": "~0.8.1"
Expand Down
2 changes: 1 addition & 1 deletion server/views/layout.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!!!
doctype
html
head
title= title_text
Expand Down

0 comments on commit fa8f15a

Please sign in to comment.