<commit_before>'use strict';

var perfcounter = require('..'),
    should = require('should'),
    assert = require('assert'),
    fmt = require('util').format;

describe('perfcounter', function () {
  it('should measure delay between start() and stop()', function (done) {
    var profile = perfcounter.start('Total');

    setTimeout(function () {
      profile.stop();

      var result = profile.result;
      var total = result.total;
      assert.ok(120 > total && total >= 100,
        fmt('Expect total time %d to be about 100', total));

      assert.ok(Math.abs(total - (result.end - result.start)) < 1,
        fmt('Expect start/stop difference %d to be about total time',
          (result.end - result.start), total));

      done();
    }, 100);
  });

  it('should measure delay between nested start() and stop()', function (done) {
    var profile = perfcounter.start('Total');

    setTimeout(function () {
      profile.start('Job1');
      profile.start('Job2');
      setTimeout(function () {
        profile.stop('Job1');

        profile.start('Job2/Subjob');
        setTimeout(function () {
          profile.stop('Job2/Subjob');
          profile.stop('Job2');
          profile.stop();

          var result = profile.result;
          var total = result.total;
          var elapsed1 = result.children[0].total;
          var elapsed2 = result.children[1].total;
          var elapsed21 = result.children[1].children[0].total;

          assert.ok(230 > total && total >= 210,
            fmt('Expect total time %d to be about 210', total));
          assert.ok(120 > elapsed1 && elapsed1 >= 100,
            fmt('Expect Job1 time %d to be about 100', elapsed1));
          assert.ok(130 > elapsed2 && elapsed2 >= 110,
            fmt('Expect Job2 time %d to be about 110', elapsed2));
          assert.ok(30 > elapsed21 && elapsed21 >= 10,
            fmt('Expect Job2/Subjob time %d to be about 10', elapsed21));

          done();
        }, 10);
      }, 100);
    }, 100);
  });

  it('should calculate missed coverage', function (done) {
    var profile = perfcounter.start('Total');

    setTimeout(function () {
      profile.start('Job');
      setTimeout(function () {
        profile.stop('Job');
        profile.stop();

        var result = profile.result;
        var missed = result.missed;
        assert.ok(120 > missed && missed >= 100,
          fmt('Expect missed time %d to be about 100', missed));<commit_msg>increase allowed error in delays<commit_after>'use strict';

var perfcounter = require('..'),
    should = require('should'),
    assert = require('assert'),
    fmt = require('util').format;

describe('perfcounter', function () {
  it('should measure delay between start() and stop()', function (done) {
    var profile = perfcounter.start('Total');

    setTimeout(function () {
      profile.stop();

      var result = profile.result;
      var total = result.total;
      assert.ok(120 > total && total >= 90,
        fmt('Expect total time %d to be about 100', total));

      assert.ok(Math.abs(total - (result.end - result.start)) < 1,
        fmt('Expect start/stop difference %d to be about total time',
          (result.end - result.start), total));

      done();
    }, 100);
  });

  it('should measure delay between nested start() and stop()', function (done) {
    var profile = perfcounter.start('Total');

    setTimeout(function () {
      profile.start('Job1');
      profile.start('Job2');
      setTimeout(function () {
        profile.stop('Job1');

        profile.start('Job2/Subjob');
        setTimeout(function () {
          profile.stop('Job2/Subjob');
          profile.stop('Job2');
          profile.stop();

          var result = profile.result;
          var total = result.total;
          var elapsed1 = result.children[0].total;
          var elapsed2 = result.children[1].total;
          var elapsed21 = result.children[1].children[0].total;

          assert.ok(230 > total && total >= 200,
            fmt('Expect total time %d to be about 210', total));
          assert.ok(120 > elapsed1 && elapsed1 >= 90,
            fmt('Expect Job1 time %d to be about 100', elapsed1));
          assert.ok(130 > elapsed2 && elapsed2 >= 100,
            fmt('Expect Job2 time %d to be about 110', elapsed2));
          assert.ok(30 > elapsed21 && elapsed21 >= 0,
            fmt('Expect Job2/Subjob time %d to be about 10', elapsed21));

          done();
        }, 10);
      }, 100);
    }, 100);
  });

  it('should calculate missed coverage', function (done) {
    var profile = perfcounter.start('Total');

    setTimeout(function () {
      profile.start('Job');
      setTimeout(function () {
        profile.stop('Job');
        profile.stop();

        var result = profile.result;
        var missed = result.missed;
        assert.ok(120 > missed && missed >= 90,
          fmt('Expect missed time %d to be about 100', missed));
{'fraction_non_alphanumeric': 0.14925978503346177, 'fraction_numerical': 0.03650375177448793, 'mean_word_length': 2.3803975325565454, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '6167646', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1359, 'n_words': 385}