<commit_before>"use strict";

const fs = require("fs");

const Benchmark = require("benchmark");

const solve = require("../lib/quadprog").solveQP;

const suite = new Benchmark.Suite("quadprog");

function wsolve(file) {
    const { Dmat, dvec, Amat, bvec, meq, factorized } = JSON.parse(fs.readFileSync(file));

    [Dmat, Amat].forEach(m => m.forEach(r => r.unshift(0)));
    [Dmat, dvec, Amat, bvec].forEach(v => v.unshift([]));

    function wrapped() {
        solve(Dmat.map(r => r.slice()), dvec.slice(), Amat.map(r => r.slice()), bvec.slice(), meq, [, factorized ? 1 : 0]); // eslint-disable-line no-sparse-arrays
    }
    return wrapped;
}

fs.readdirSync("test")
    .filter(f => f.endsWith("-data.json"))
    .forEach(f => suite.add(f.slice(0, -10), wsolve(`test/${f}`)));<commit_msg>Reformat bench.js and fix a vscode linter error.<commit_after>"use strict";

const fs = require("fs");

const Benchmark = require("benchmark");

const solve = require("../lib/quadprog").solveQP;

const suite = new Benchmark.Suite("quadprog");

function wsolve(file) {
    const {
        Dmat,
        dvec,
        Amat,
        bvec,
        meq,
        factorized
    } = JSON.parse(fs.readFileSync(file).toString());

    [Dmat, Amat].forEach(m => m.forEach(r => r.unshift(0)));
    [Dmat, dvec, Amat, bvec].forEach(v => v.unshift([]));

    function wrapped() {
        solve(
            Dmat.map(r => r.slice()),
            dvec.slice(),
            Amat.map(r => r.slice()),
            bvec.slice(),
            meq,
            [, factorized ? 1 : 0] // eslint-disable-line no-sparse-arrays
        );
    }
    return wrapped;
}

fs.readdirSync("test")
    .filter(f => f.endsWith("-data.json"))
    .forEach(f => suite.add(f.slice(0, -10), wsolve(`test/${f}`)));
{'fraction_non_alphanumeric': 0.1992099322799097, 'fraction_numerical': 0.006772009029345372, 'mean_word_length': 2.7965738758029977, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '5471769', 'n_tokens_mistral': 647, 'n_tokens_neox': 627, 'n_words': 121}