<commit_before>var actionheroPrototype = require(__dirname + '/../../actionhero.js').actionheroPrototype;
var actionhero = new actionheroPrototype();
var uuid = require('node-uuid');
var api;
var messages = [];

var multiAction = function(action, count, params, next){
  var inFlight = 0;
  var i = 0;
  var start = new Date().getTime();
  while(i < count){
    inFlight++;
    var theseParams = {};
    for(var x in params){
      theseParams[x] = params[x];
      if(typeof theseParams[x] === 'function'){
        theseParams[x] = theseParams[x]();
      }
    }
    api.specHelper.runAction(action, theseParams, function(){
      inFlight--;
      if(inFlight === 0){
        var durationSeconds = ((new Date().getTime()) - start) / 1000;
        messages.push('benchmark: action: ' + action + ' x ' + count + ' >>> ' + durationSeconds + 's');
        next(durationSeconds);
      }
    });
    i++;
  }
};

describe('Benchmarks', function(){

  before(function(done){
    actionhero.start(function(error, a){
      api = a;
      done();
    });
  });

  after(function(done){
    actionhero.stop(function(){
      console.log('');
      console.log('');
      messages.forEach(function(message){
        console.log(message);
      });
      done();
    });
  });

  it('randomNumber', function(done){
    this.timeout(20 * 1000);
    multiAction('randomNumber', 1000, {}, function(){
      done();
    });
  });

  it('status', function(done){
    this.timeout(20 * 1000);
    multiAction('status', 1000, {}, function(){
      done();
    });
  });

  it('cacheTest', function(done){<commit_msg>do less status actions in the benchmark<commit_after>var actionheroPrototype = require(__dirname + '/../../actionhero.js').actionheroPrototype;
var actionhero = new actionheroPrototype();
var uuid = require('node-uuid');
var api;
var messages = [];

var multiAction = function(action, count, params, next){
  var inFlight = 0;
  var i = 0;
  var start = new Date().getTime();
  while(i < count){
    inFlight++;
    var theseParams = {};
    for(var x in params){
      theseParams[x] = params[x];
      if(typeof theseParams[x] === 'function'){
        theseParams[x] = theseParams[x]();
      }
    }
    api.specHelper.runAction(action, theseParams, function(){
      inFlight--;
      if(inFlight === 0){
        var durationSeconds = ((new Date().getTime()) - start) / 1000;
        messages.push('benchmark: action: ' + action + ' x ' + count + ' >>> ' + durationSeconds + 's');
        next(durationSeconds);
      }
    });
    i++;
  }
};

describe('Benchmarks', function(){

  before(function(done){
    actionhero.start(function(error, a){
      api = a;
      done();
    });
  });

  after(function(done){
    actionhero.stop(function(){
      console.log('');
      console.log('');
      messages.forEach(function(message){
        console.log(message);
      });
      done();
    });
  });

  it('randomNumber', function(done){
    this.timeout(20 * 1000);
    multiAction('randomNumber', 1000, {}, function(){
      done();
    });
  });

  it('status', function(done){
    this.timeout(20 * 1000);
    multiAction('status', 100, {}, function(){
      done();
    });
  });

  it('cacheTest', function(done){
{'fraction_non_alphanumeric': 0.18593120545398203, 'fraction_numerical': 0.01642392314843508, 'mean_word_length': 2.884476534296029, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4131780', 'n_tokens_mistral': 1045, 'n_tokens_neox': 990, 'n_words': 207}