diff --git a/bench/data.js b/bench/data.js deleted file mode 100644 index 0ab99658..00000000 --- a/bench/data.js +++ /dev/null @@ -1,60 +0,0 @@ -window.BENCHMARK_DATA = { - "lastUpdate": 1690122626630, - "repoUrl": "https://github.com/CanadaHonk/porffor", - "entries": { - "porffor benches": [ - { - "commit": { - "author": { - "email": "oj@oojmed.com", - "name": "CanadaHonk", - "username": "CanadaHonk" - }, - "committer": { - "email": "oj@oojmed.com", - "name": "CanadaHonk", - "username": "CanadaHonk" - }, - "distinct": true, - "id": "ace1cb1dec46a0c83a7ec42d4c6f3bbf13338d89", - "message": "bench ci: add perms to write\n\ntest262: 10.84% | 🧪 48843 | 🤠 5295 | ❌ 942 | 💀 8183 | 🧩 143 | 💥 3344 | 📝 30936", - "timestamp": "2023-07-23T15:28:42+01:00", - "tree_id": "a6312ce910036c7d1ca6eced6029f2e3fffc85b4", - "url": "https://github.com/CanadaHonk/porffor/commit/ace1cb1dec46a0c83a7ec42d4c6f3bbf13338d89" - }, - "date": 1690122626609, - "tool": "benchmarkjs", - "benches": [ - { - "name": "node countPrimes(10000)", - "value": 33.12, - "range": "±0.87%", - "unit": "ops/sec", - "extra": "57 samples" - }, - { - "name": "porffor countPrimes(10000)", - "value": 36.58, - "range": "±0.84%", - "unit": "ops/sec", - "extra": "62 samples" - }, - { - "name": "node randoms(10000)", - "value": 7969, - "range": "±0.71%", - "unit": "ops/sec", - "extra": "88 samples" - }, - { - "name": "porffor randoms(10000)", - "value": 15834, - "range": "±1.04%", - "unit": "ops/sec", - "extra": "85 samples" - } - ] - } - ] - } -} \ No newline at end of file diff --git a/bench/index.html b/bench/index.html index 6c887805..310a99bb 100644 --- a/bench/index.html +++ b/bench/index.html @@ -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); } @@ -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: { @@ -201,7 +217,7 @@ { scaleLabel: { display: true, - labelString: dataset.length > 0 ? dataset[0].bench.unit : '', + labelString: unit + ' (lower is better)' }, ticks: { beginAtZero: true, @@ -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 : ''; } } }, @@ -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); } } diff --git a/bench/randoms.js b/bench/randoms.js new file mode 100644 index 00000000..85c8136f --- /dev/null +++ b/bench/randoms.js @@ -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); \ No newline at end of file diff --git a/bench_ci/bench.js b/bench_ci/bench.js index 9f9c9e6e..360eae69 100644 --- a/bench_ci/bench.js +++ b/bench_ci/bench.js @@ -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