Skip to content

Commit

Permalink
bench ci: improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
CanadaHonk committed Jul 23, 2023
1 parent 5679541 commit bfc78b4
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 88 deletions.
60 changes: 0 additions & 60 deletions bench/data.js

This file was deleted.

66 changes: 41 additions & 25 deletions bench/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,24 @@
_: '#333333'
};

const projectColors = {
node: '#5dae47',
porffor: '#9c60e0'
};

const benchInfo = name => name.split(' ');

function init() {
function collectBenchesPerTestCase(entries) {
const map = new Map();
for (const entry of entries) {
const {commit, date, tool, benches} = entry;
for (const bench of benches) {
const result = { commit, date, tool, bench };
const arr = map.get(bench.name);
const [ project, name ] = benchInfo(bench.name);
const result = { commit, date, tool, bench, project };
const arr = map.get(name);
if (arr === undefined) {
map.set(bench.name, [result]);
map.set(name, [result]);
} else {
arr.push(result);
}
Expand Down Expand Up @@ -169,23 +177,31 @@
}

function renderAllChars(dataSets) {

function renderGraph(parent, name, dataset) {
const canvas = document.createElement('canvas');
canvas.className = 'benchmark-chart';
parent.appendChild(canvas);

const color = toolColors[dataset.length > 0 ? dataset[0].tool : '_'];
const datasets = new Map();
for (const x of dataset) {
if (!datasets.get(x.project)) {
const color = projectColors[x.project.split('(')[0]];
datasets.set(x.project, {
label: x.project,
data: [],
borderColor: color,
backgroundColor: color + '60'
});
}

datasets.get(x.project).data.push((1 / x.bench.value) * 1000);
}

const unit = 'ms';

const data = {
labels: dataset.map(d => d.commit.id.slice(0, 7)),
datasets: [
{
label: name,
data: dataset.map(d => d.bench.value),
borderColor: color,
backgroundColor: color + '60', // Add alpha for #rrggbbaa
}
],
datasets: [...datasets.values()]
};
const options = {
scales: {
Expand All @@ -201,7 +217,7 @@
{
scaleLabel: {
display: true,
labelString: dataset.length > 0 ? dataset[0].bench.unit : '',
labelString: unit + ' (lower is better)'
},
ticks: {
beginAtZero: true,
Expand All @@ -211,23 +227,19 @@
},
tooltips: {
callbacks: {
afterTitle: items => {
const {index} = items[0];
title: items => {
const { index, label } = items[0];
const data = dataset[index];
return '\n' + data.commit.message + '\n\n' + data.commit.timestamp + ' committed by @' + data.commit.committer.username + '\n';
return label + ': ' + data.commit.message.split('\n')[0].trim() + '\n' + new Date(data.commit.timestamp).toString();
},
label: item => {
let label = item.value;
const { range, unit } = dataset[item.index].bench;
let label = 1 / item.value;
const { extra, range } = dataset[item.index].bench;
label += ' ' + unit;
if (range) {
label += ' (' + range + ')';
label += ' (' + extra + ', ' + range + ')';
}
return label;
},
afterLabel: item => {
const { extra } = dataset[item.index].bench;
return extra ? '\n' + extra : '';
}
}
},
Expand Down Expand Up @@ -264,7 +276,11 @@
setElem.appendChild(graphsElem);

for (const [benchName, benches] of benchSet.entries()) {
renderGraph(graphsElem, benchName, benches)
const headerElem = document.createElement('h2');
headerElem.textContent = benchName;
graphsElem.appendChild(headerElem);

renderGraph(graphsElem, benchName, benches);
}
}

Expand Down
12 changes: 12 additions & 0 deletions bench/randoms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function randoms(max) {
let sum = 0;
for (let i = 0; i < max; i++) {
sum += Math.random();
}

return sum;
}

let t = performance.now();
randoms(10000);
console.log(performance.now() - t);
14 changes: 11 additions & 3 deletions bench_ci/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ const suite = new Benchmark.Suite();
const funcs = [ countPrimes, randoms ];
const max = 10000;
for (const x of funcs) {
const compiled = (await compile('export ' + x.toString())).exports[x.name];

suite.add(`node ${x.name}(${max})`, () => {
x(max);
});

suite.add(`porffor ${x.name}(${max})`, () => {
const compiled = (await compile('export ' + x.toString())).exports[x.name];

suite.add(`porffor(default) ${x.name}(${max})`, () => {
compiled(max);
});

process.argv.push('-valtype=i32');
const compiledI32 = (await compile('export ' + x.toString())).exports[x.name];
process.argv.pop();

suite.add(`porffor(i32) ${x.name}(${max})`, () => {
compiledI32(max);
});
}

suite
Expand Down

0 comments on commit bfc78b4

Please sign in to comment.