<commit_before>'use strict';

/* eslint-disable no-cond-assign */

var fixtures, franc, guesslanguage, languagedetect, Vac;

franc = require('..');
fixtures = require('../spec/fixtures.json');

try {
    guesslanguage = require('guesslanguage').guessLanguage;
    languagedetect = new (require('languagedetect'))();
    Vac = require('vac');
} catch (error) {
    console.log(error);
    throw new Error(
        '\u001B[0;31m' +
        'The libraries needed by this benchmark could not be found. ' +
        'Please execute:\n' +
        '\tnpm run install-benchmark\n\n' +
        '\u001B[0m'
    );
}

function guessLanguage(fixture) {
    var result;
    guesslanguage.detect(fixture, function (language) {
        result = language;
    });
    return result;
}

function languageDetect(fixture) {
    var result = languagedetect.detect(fixture, 1)[0];
    return result && result[0];
}

function vac(fixture) {
    return Object.keys(Vac.detect(fixture, 1))[0];
}

function forEveryLanguage(callback) {
    var language;

    for (language in fixtures) {
        callback(language, fixtures[language]);
    }
}

suite('benchmarks * 82 paragraphs in different languages', function () {
    set('iterations', 30);
    set('type', 'static');

    bench('franc -- this module', function () {
        forEveryLanguage(function (language, fixture) {
            franc(fixture);
        });
    });

    bench('guesslanguage', function () {
        forEveryLanguage(function (language, fixture) {
            guessLanguage(fixture);
        });
    });

    bench('languagedetect', function () {
        forEveryLanguage(function (language, fixture) {
            languageDetect(fixture);
        });
    });

    bench('vac', function () {
        forEveryLanguage(function (language, fixture) {
            vac(fixture);
        });
    });
});<commit_msg>Refactor benchmark for new variable support<commit_after>'use strict';

/* eslint-disable no-cond-assign */

var fixtures, franc, guesslanguage, languagedetect, Vac;

franc = require('..');
fixtures = require('../spec/fixtures.json');

try {
    guesslanguage = require('guesslanguage').guessLanguage;
    languagedetect = new (require('languagedetect'))();
    Vac = require('vac');
} catch (error) {
    console.log(error);
    throw new Error(
        '\u001B[0;31m' +
        'The libraries needed by this benchmark could not be found. ' +
        'Please execute:\n' +
        '\tnpm run install-benchmark\n\n' +
        '\u001B[0m'
    );
}

function guessLanguage(fixture) {
    var result;
    guesslanguage.detect(fixture, function (language) {
        result = language;
    });
    return result;
}

function languageDetect(fixture) {
    var result = languagedetect.detect(fixture, 1)[0];
    return result && result[0];
}

function vac(fixture) {
    return Object.keys(Vac.detect(fixture, 1))[0];
}

function forEveryLanguage(callback) {
    var language;

    for (language in fixtures) {
        callback(language, fixtures[language]);
    }
}

suite(
    'benchmarks * ' +
    Object.keys(fixtures).length +
    ' paragraphs in different languages',
    function () {
        set('iterations', 10);
        set('type', 'static');

        bench('franc -- this module', function () {
            forEveryLanguage(function (language, fixture) {
                franc(fixture);
            });
        });

        bench('guesslanguage', function () {
            forEveryLanguage(function (language, fixture) {
                guessLanguage(fixture);
            });
        });

        bench('languagedetect', function () {
            forEveryLanguage(function (language, fixture) {
                languageDetect(fixture);
            });
        });

        bench('vac', function () {
            forEveryLanguage(function (language, fixture) {
                vac(fixture);
            });
        });
    }
);
{'fraction_non_alphanumeric': 0.1424164524421594, 'fraction_numerical': 0.009254498714652956, 'mean_word_length': 2.5501824817518246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2083882', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1121, 'n_words': 240}