Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 39 additions & 32 deletions worker/bomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

let cycleCount = 20;

let maxWorkers = 8;
let resolve = null;

let numWorkers = 0;

function startWorker(file) {
numWorkers++;
let worker = new Worker(file);
Expand All @@ -40,52 +39,60 @@ function startWorker(file) {
};
}

function startCycle() {
function startCycle(iteration) {
if (!isInBrowser)
throw new Error("Only works in browser");

const tests = [
rayTrace3D
, accessNbody
, morph3D
, cube3D
, accessFunnkuch
, accessBinaryTrees
, accessNsieve
, bitopsBitwiseAnd
, bitopsNsieveBits
, controlflowRecursive
, bitops3BitBitsInByte
, botopsBitsInByte
, cryptoAES
, cryptoMD5
, cryptoSHA1
, dateFormatTofte
, dateFormatXparb
, mathCordic
, mathPartialSums
, mathSpectralNorm
, stringBase64
, stringFasta
, stringValidateInput
, stringTagcloud
, stringUnpackCode
, regexpDNA
rayTrace3D,
accessNbody,
morph3D,
cube3D,
accessFunnkuch,
accessBinaryTrees,
accessNsieve,
bitopsBitwiseAnd,
bitopsNsieveBits,
controlflowRecursive,
bitops3BitBitsInByte,
botopsBitsInByte,
cryptoAES,
cryptoMD5,
cryptoSHA1,
dateFormatTofte,
dateFormatXparb,
mathCordic,
mathPartialSums,
mathSpectralNorm,
stringBase64,
stringFasta,
stringValidateInput,
stringTagcloud,
stringUnpackCode,
regexpDNA,
];

for (let test of tests)
for (let i = 0; i < maxWorkers; i++) {
const testIndex = i + iteration * numWorkers;
const test = tests[testIndex % tests.length];
startWorker(test);
}

}


class Benchmark {
constructor() {
this.iteration = 0;
}

async runIteration() {
if (numWorkers !== 0 || resolve)
throw new Error("Something bad happened.");
this.iteration++;

let promise = new Promise((res) => resolve = res);
startCycle();
startCycle(this.iteration);
await promise;
resolve = null;
}
Expand Down
Loading