Skip to content

Commit

Permalink
Use block function for onmessage
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed May 17, 2017
1 parent fdbdfc5 commit 34f9fb7
Showing 1 changed file with 52 additions and 49 deletions.
101 changes: 52 additions & 49 deletions test/bench/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,66 @@ function getCell(bench) {
return parserNames.indexOf(bench.name);
}

onmessage = ({ data: indices }) => inputs.then(inputs => {
let chosenParsers =
parserNames
.filter((_, i) => indices.includes(i))
.map(name => Object.assign(parsers[name](), { name }));
onmessage = ({ data: indices }) => {
// Using block to workaround https://github.com/Microsoft/ChakraCore/issues/2606
inputs.then(inputs => {
let chosenParsers =
parserNames
.filter((_, i) => indices.includes(i))
.map(name => Object.assign(parsers[name](), { name }));

postMessage({
type: 'versions',
versions: chosenParsers.map(parser => parser.version)
});

inputs.forEach((input, row) => {
let suite = new Benchmark.Suite();

chosenParsers.forEach(({ name, parse }) => {
suite.add(name, () => parse(input));
postMessage({
type: 'versions',
versions: chosenParsers.map(parser => parser.version)
});

let indicesIter = indices[Symbol.iterator]();
inputs.forEach((input, row) => {
let suite = new Benchmark.Suite();

console.group(`Parsing ${inputNames[row]}`);
chosenParsers.forEach(({ name, parse }) => {
suite.add(name, () => parse(input));
});

postMessage({
type: 'start',
row,
cell: indicesIter.next().value
});
let indicesIter = indices[Symbol.iterator]();

function reportCell(bench, type, text) {
postMessage({
type,
row,
cell: getCell(bench),
nextCell: indicesIter.next().value,
text
});
}
console.group(`Parsing ${inputNames[row]}`);

suite
.on('cycle', ({ target: bench }) => {
console.log(bench.toString());
reportCell(bench, 'cycle', `${bench.hz.toFixed(2)} ops/sec`);
})
.on('error', ({ target: bench }) => {
console.error(bench.error);
reportCell(bench, 'error', bench.error.name);
})
.on('complete', ({ target }) => {
postMessage({
type: 'complete',
type: 'start',
row,
slowest: suite.filter('slowest').map(getCell),
fastest: suite.filter('fastest').map(getCell)
cell: indicesIter.next().value
});
})
.run();

console.groupEnd();
});
}).catch(console.error);
function reportCell(bench, type, text) {
postMessage({
type,
row,
cell: getCell(bench),
nextCell: indicesIter.next().value,
text
});
}

suite
.on('cycle', ({ target: bench }) => {
console.log(bench.toString());
reportCell(bench, 'cycle', `${bench.hz.toFixed(2)} ops/sec`);
})
.on('error', ({ target: bench }) => {
console.error(bench.error);
reportCell(bench, 'error', bench.error.name);
})
.on('complete', ({ target }) => {
postMessage({
type: 'complete',
row,
slowest: suite.filter('slowest').map(getCell),
fastest: suite.filter('fastest').map(getCell)
});
})
.run();

console.groupEnd();
});
}).catch(console.error);
};

0 comments on commit 34f9fb7

Please sign in to comment.