Navigation Menu

Skip to content

Commit

Permalink
support for meanTime in results
Browse files Browse the repository at this point in the history
  • Loading branch information
brianc committed Dec 25, 2010
1 parent dbfd70d commit 6872e3c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
10 changes: 10 additions & 0 deletions lib/index.js
Expand Up @@ -28,11 +28,21 @@ var bench = function(config) {
}
action.repeat = config.repeat;
executeAction(action, function() {
aggregateActionResults(action)
doAction(config.actions[i++])
})
}
doAction(config.actions[i++]);
}
}

var aggregateActionResults = function(action) {
var times = action.repeats.map(function(repeat) {
return repeat.end - repeat.start
})
action.meanTime = (times.reduce(function(prev, next) {
return prev + next
})/action.repeats.length)
}

module.exports = bench
20 changes: 13 additions & 7 deletions test/result-tests.js
Expand Up @@ -22,15 +22,21 @@ test('results', function() {
result.actions.length.should.equal(2)

test('first action',function() {
var firstAction = result.actions[0]
firstAction.name.should.equal('first')
firstAction.repeats.length.should.equal(10)
firstAction.repeats.forEach(function(repeat) {
repeat.start.should.be.instanceof(Date)
repeat.end.should.be.instanceof(Date)
var action = result.actions[0]
action.name.should.equal('first')
test('repeat data', function() {
action.repeats.length.should.equal(10)
action.repeats.forEach(function(repeat) {
repeat.start.should.be.instanceof(Date)
repeat.end.should.be.instanceof(Date)
})
})

test('rollup data', function() {
action.meanTime.should.be.within(9, 11)
})

})

}))
})

0 comments on commit 6872e3c

Please sign in to comment.