INNER CODE UNIT · JavaScript
sortTrials
m4heshd/better-sqlite3-multiple-ciphers · benchmark/index.js:25
const sortTrials = (a, b) => {
const aRo = require(`./types/${a.type}`).readonly;
const bRo = require(`./types/${b.type}`).readonly;
if (typeof aRo !== 'boolean') throw new TypeError(`Missing readonly export in benchmark type ${a.type}`);
if (typeof bRo !== 'boolean') throw new TypeError(`Missing readonly export in benchmark type ${b.type}`);
return bRo - aRo;
};
const displayTrialName = (trial) => {
if (trial.description) return console.log(clc.magenta(`--- ${trial.description} ---`));
const name = `${trial.type} ${trial.table} (${trial.columns.join(', ')})`;
const pragma = trial.customPragma.length ? ` | ${trial.customPragma.join('; ')}` : '';
console.log(clc.magenta(name) + clc.yellow(pragma));
};
const createContext = (trial, driver) => {
const tableInfo = Object.assign({}, tables.get(trial.table), { data: undefined });
return JSON.stringify(Object.assign({}, trial, tableInfo, { driver, tables: [...tables.keys()] }));