From 28117353a9a317bc7438ab75f2f44f3fc4c23960 Mon Sep 17 00:00:00 2001 From: Don Alfons Nisnoni Date: Wed, 20 Nov 2019 22:59:37 +0800 Subject: [PATCH] tools/fast.v: calculate the difference between current and previous results --- tools/fast/.gitignore | 3 ++ tools/fast/fast.v | 10 +++---- tools/fast/footer.html | 4 +++ tools/fast/header.html | 23 ++++++++++++-- tools/fast/main.js | 68 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 tools/fast/.gitignore create mode 100644 tools/fast/footer.html create mode 100644 tools/fast/main.js diff --git a/tools/fast/.gitignore b/tools/fast/.gitignore new file mode 100644 index 0000000000..af2ddc5deb --- /dev/null +++ b/tools/fast/.gitignore @@ -0,0 +1,3 @@ +fast +v2 +index.html diff --git a/tools/fast/fast.v b/tools/fast/fast.v index bf0db40ff3..d5eaefb2e9 100644 --- a/tools/fast/fast.v +++ b/tools/fast/fast.v @@ -56,16 +56,18 @@ fn main() { out.close() // Regenerate index.html header := os.read_file('header.html') or { panic(err) } + footer := os.read_file('footer.html') or { panic(err) } res := os.create('index.html') or { panic(err) } res.writeln(header) res.writeln(table) + res.writeln(footer) res.close() -} +} fn exec(s string) string { e := os.exec(s) or { panic(err) } return e.output -} +} // returns milliseconds fn measure(cmd string) int { @@ -77,6 +79,4 @@ fn measure(cmd string) int { ticks := time.ticks() exec(cmd) return int(time.ticks() - ticks) -} - - +} diff --git a/tools/fast/footer.html b/tools/fast/footer.html new file mode 100644 index 0000000000..37f5c0f5e9 --- /dev/null +++ b/tools/fast/footer.html @@ -0,0 +1,4 @@ + + + + diff --git a/tools/fast/header.html b/tools/fast/header.html index 49076c35c6..700b65408d 100644 --- a/tools/fast/header.html +++ b/tools/fast/header.html @@ -1,9 +1,12 @@ + + + Is V still fast? @@ -31,4 +51,3 @@ Source code: v -o v -fast v hello.v - diff --git a/tools/fast/main.js b/tools/fast/main.js new file mode 100644 index 0000000000..0ae0d6fa9b --- /dev/null +++ b/tools/fast/main.js @@ -0,0 +1,68 @@ +(function () { + var table = document.querySelector("table"); + var isTbody = table.children[0].nodeName == "TBODY"; + var trs = isTbody + ? table.children[0].querySelectorAll("tr") + : table.querySelectorAll("tr"); + trs.forEach(function (tr, idx) { + if (idx != 0 && idx + 1 < trs.length) { + var vc = 3, vv = 4, vf = 5, vh = 6; + var textContent = { + vc: tr.children[vc].textContent, + vv: tr.children[vv].textContent, + vf: tr.children[vf].textContent, + vh: tr.children[vh].textContent + }; + var currentData = { + vc: int(textContent.vc.slice(0, -2)), + vv: int(textContent.vv.slice(0, -2)), + vf: int(textContent.vf.slice(0, -2)), + vh: int(textContent.vh.slice(0, -2)) + }; + var prevData = { + vc: int(trs[idx + 1].children[vc].textContent.slice(0, -2)), + vv: int(trs[idx + 1].children[vv].textContent.slice(0, -2)), + vf: int(trs[idx + 1].children[vf].textContent.slice(0, -2)), + vh: int(trs[idx + 1].children[vh].textContent.slice(0, -2)) + }; + var result = { + vc: currentData.vc - prevData.vc, + vv: currentData.vv - prevData.vv, + vf: currentData.vf - prevData.vf, + vh: currentData.vh - prevData.vh + }; + if (Math.abs(result.vc) > 50) + tr.children[vc].appendChild(createElement(result.vc)); + if (Math.abs(result.vv) > 50) + tr.children[vv].appendChild(createElement(result.vv)); + if (Math.abs(result.vf) > 50) + tr.children[vf].appendChild(createElement(result.vf)); + if (Math.abs(result.vh) > 50) + tr.children[vh].appendChild(createElement(result.vh)); + } + }); + function int(src) { + return src - 0; + } + function str(src) { + return src + ""; + } + function getClassName(x) { + if (x == 0) + return "equal"; + return x < 0 ? "plus" : "minus"; + } + function createElement(result) { + var el = document.createElement("span"); + var parsedResult = parseResult(result); + el.classList.add("diff"); + el.classList.add(getClassName(result)); + el.textContent = parsedResult; + return el; + } + function parseResult(x) { + if (x == 0) + return "0"; + return x > 0 ? "+" + x : x; + } +})();