iso-bench
Version:
Small benchmark library focused in avoiding optimization/deoptimization pollution between tests by isolating them.
53 lines (52 loc) • 1.73 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Test = void 0;
const Messager_1 = require("./Messager");
const getDiff_1 = require("./getDiff");
const ForkContext_1 = require("./ForkContext");
class Test {
name;
index;
options;
_cb;
error = null;
opMs = 0;
totalTime = 0;
samples = [];
group = "";
constructor(name, index, options, _cb) {
this.name = name;
this.index = index;
this.options = options;
this._cb = _cb;
}
fork(benchName, processors, options) {
return new Promise((resolve => {
const forkContext = new ForkContext_1.ForkContext(this, processors, resolve, benchName);
forkContext.start();
}));
}
setGroup(name) {
this.group = name;
}
async run() {
(0, getDiff_1.getDiff)(1, this._cb.callback, this._cb.setup);
let cycles = 1;
let samples = this.options.samplesPerSpawn;
do {
const diff = (0, getDiff_1.getDiff)(cycles, this._cb.callback, this._cb.setup);
if (this.options.customCycles != null || diff >= this.options.time) {
samples--;
await Messager_1.Messager.send({
diff: diff,
cycles: this.options.customCycles != null ? this.options.customCycles : cycles
});
}
if (this.options.customCycles == null) {
const ratio = diff > 0 ? (this.options.time / diff) * 1.02 : 1.1;
cycles = diff >= this.options.time ? Math.round(cycles * ratio) : Math.ceil(cycles * ratio);
}
} while (samples > 0);
}
}
exports.Test = Test;
;