Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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");
Add Comment
Please, Sign In to add comment