Skip to content

Proposal: bomb-workers add upper limit #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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