Skip to content

Instantly share code, notes, and snippets.

@bluepichu
Created November 19, 2017 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluepichu/b23de2bd18b5b4f1c9191fe3b011dc88 to your computer and use it in GitHub Desktop.
Save bluepichu/b23de2bd18b5b4f1c9191fe3b011dc88 to your computer and use it in GitHub Desktop.
15411 L5 Tabulator
const express = require("express");
const chroma = require("chroma-js");
const fs = require("fs-extra");
const app = express();
const scaleGood = chroma.scale(["blue", "green"]);
const scaleOk = chroma.scale(["yellow", "orange"]);
const scaleBad = chroma.scale(["red", "black"]);
let gcc = new Map([
["cell.l4", 310422],
["collatz.l4", 89811],
["fibrec.l4", 164551],
["floyd.l4", 191644],
["gcd.l4", 245165],
["list.l4", 354856],
["mmult2.l4", 167739],
["mmult.l4", 292616],
["msort.l4", 97452],
["prime.l4", 83499],
["qsort.l4", 321400],
["shifts.l4", 94324],
["tree.l4", 139278],
["avl.l4", 5724362],
["hashtable.l4", 1446232],
["heaps.l4", 6023667],
["md5.l4", 2557570]
]);
app.get("/", (req, res) => {
fs.readFile("last.log")
.then((data) => {
data = data.toString();
data = data.split(/-- Timing file .*\/([a-z0-9]+\.l4) --/);
data = data.slice(1);
map = new Map();
for (let i = 0; i < data.length; i += 2) {
let key = data[i];
let value =
data[i+1]
.split("\n")
.slice(1,7)
.map((v) => {
let match = /.*?(\d{3,}).*/.exec(v);
return match === null ? null : parseInt(match[1]);
})
value = value.reduce((a, b) => a == null ? null : (b == null ? null : Math.min(a, b)));
map.set(key, value);
}
let out = `
<html>
<head><style>th, td { padding: .4em }</style></head>
<body>
<h1>Testing Results</h1>
<table>
<tr><th>Test file</th><th>Your Cycles</th><th>GCC Cycles</th><th>Performance</th></tr>`;
let perfScore = 0;
for (let [file, gccCycles] of gcc) {
let yourCycles = map.get(file);
if (yourCycles == null) {
out += `\n<tr style="background-color: black; color: white;"><td>${file}</td><td><b>FAILED</b></td><td>${gccCycles}</td><td><b>FAILED</b></td></tr>`;
perfScore = NaN;
} else {
let perf = yourCycles / gccCycles;
let color = "red";
if (perf <= .7){
color = scaleGood(perf / .7);
} else if (perf <= 1) {
color = scaleOk((perf - .7) / .3);
} else {
color = scaleBad((perf - 1) / .4);
}
out += `\n<tr style="background-color: ${color.hex()}; color: white;"><td>${file}</td><td>${yourCycles}</td><td>${gccCycles}</td><td>${Math.round(perf*1000)/1000}</td></tr>`;
perfScore += perf;
}
}
perfScore /= gcc.size;
out += `\n</table><h2>Final perf score: ${isNaN(perfScore) ? "FAILED" : Math.round(perfScore*10000)/10000}</body></html>`;
res.send(out);
});
});
app.listen(1337);
console.log("Listening on *:1337");
{
"name": "serve-table",
"version": "1.0.0",
"description": "## Introduction",
"main": "index.js",
"directories": {
"test": "tests"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/CMU-15-411-F17/robert.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/CMU-15-411-F17/robert/issues"
},
"homepage": "https://github.com/CMU-15-411-F17/robert#readme",
"dependencies": {
"chroma-js": "^1.3.4",
"express": "^4.16.2",
"fs-extra": "^4.0.2",
"get-stdin": "^5.0.1"
}
}
../timecompiler -q --limit-run=120 --color=off | tee /dev/tty > last.log
@bluepichu
Copy link
Author

Intended usage:

# Setup
npm install
chmod +x tabulate
node index.js &

# When you want to run tests
git pull origin your-branch-here
./tabulate

@Strikeskids
Copy link

Strikeskids commented Nov 20, 2017

Slight improvement on your run script 🤣

../timecompiler -q --limit-run=120 --color=off | tee last.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment