<commit_before>/* eslint no-console:0 */
'use strict';

/**
 * Requirements
 * @ignore
 */
const Base = require('../Base.js').Base;


/**
 * @class
 * @memberOf utils
 * @extends {Base}
 */
class StopWatch extends Base
{
    /**
     * @ignore
     */
    constructor()
    {
        super();
        this._watches = {};
    }


    /**
     * @inheritDocs
     */
    static get className()
    {
        return 'utils/StopWatch';
    }


    /**
     */
    start(name, label)
    {
        this._watches[name] = { label: label, started: Date.now() };
    }

    /**
     */
    stop(name)
    {
        if (!this._watches[name])
        {
            return;
        }
        const label = this._watches[name].label || '';
        const time = Date.now() - this._watches[name].started;
        console.log('StopWatch ' + name + ' - ' + label + ' => ' + time);
    }
}

/**
 * Exports
 * @ignore
 */
module.exports.StopWatch = StopWatch;<commit_msg>refactor(utils): adds support for multiple timers with the same name<commit_after>/* eslint no-console:0 */
'use strict';

/**
 * Requirements
 * @ignore
 */
const Base = require('../Base.js').Base;
const chalk = require('chalk');


/**
 * @class
 * @memberOf utils
 * @extends {Base}
 */
class StopWatch extends Base
{
    /**
     * @ignore
     */
    constructor()
    {
        super();
        this._watches = {};
    }


    /**
     * @inheritDocs
     */
    static get className()
    {
        return 'utils/StopWatch';
    }


    /**
     */
    start(name)
    {
        if (!this._watches[name])
        {
            this._watches[name] =
            {
                name: name,
                count: 0,
                time: 0,
                min: Number.MAX_SAFE_INTEGER,
                max: 0
            };
        }
        this._watches[name].started = Date.now();
    }


    /**
     */
    stop(name)
    {
        if (!this._watches[name])
        {
            return;
        }
        this._watches[name].count++;
        const time = Date.now() - this._watches[name].started;
        this._watches[name].time+= time;
        this._watches[name].min = Math.min(this._watches[name].min, time);
        this._watches[name].max = Math.max(this._watches[name].max, time);
        this._watches[name].average = this._watches[name].time / this._watches[name].count;
        delete this._watches[name].started;
    }


    /**
     */
    show()
    {
        console.log(chalk.bold('\nTimers:\n'));
        for (const name in this._watches)
        {
            const timer = this._watches[name];
            console.log(chalk.yellow(' ' + timer.name));
            console.log('  count: ' + timer.count + ', total: ' + timer.time + ', average: ' + timer.average.toFixed(2));
            console.log();
        }
    }


    /**
     */
    clear()
    {
        this._watches = {};
    }
}

/**
 * Exports
 * @ignore
 */
module.exports.StopWatch = StopWatch;
module.exports.stopWatch = new StopWatch();
{'fraction_non_alphanumeric': 0.1665549597855228, 'fraction_numerical': 0.0020107238605898124, 'mean_word_length': 1.6230228471001757, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6686879', 'n_tokens_mistral': 1004, 'n_tokens_neox': 946, 'n_words': 162}