tools/fast.v: calculate the difference between current and previous results

pull/2790/head
Don Alfons Nisnoni 2019-11-20 22:59:37 +08:00 committed by Alexander Medvednikov
parent 0e852e9c81
commit 28117353a9
5 changed files with 101 additions and 7 deletions

3
tools/fast/.gitignore vendored 100644
View File

@ -0,0 +1,3 @@
fast
v2
index.html

View File

@ -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)
}
}

View File

@ -0,0 +1,4 @@
</table>
<script src="main.js"></script>
</body>
</html>

View File

@ -1,9 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Is V still fast?</title>
<style>
*, body {
font-family: Menlo,Monospace,'Courier New';
font-family: Menlo, Monospace, 'Courier New';
}
table, td {
border-collapse: collapse;
@ -11,6 +14,23 @@ table, td {
}
td {
padding: 5px;
position: relative;
}
.diff {
border-radius: 2.5px;
color: #ffffff;
padding: 0 5px 0 5px;
position: absolute;
right: 5px;
}
.minus {
background-color: rgb(195, 74, 104);
}
.plus {
background-color: #8BC34A;
}
.equal {
background-color: rgb(113, 68, 172);
}
</style>
</head>
@ -31,4 +51,3 @@ Source code: <a target=blank href='https://github.com/vlang/v/blob/master/tools/
<td style='width:120px'>v -o v -fast</td>
<td style='width:120px'>v hello.v</td>
</tr>

68
tools/fast/main.js 100644
View File

@ -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;
}
})();