mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tools/fast.v: calculate the difference between current and previous results
This commit is contained in:
parent
0e852e9c81
commit
28117353a9
3
tools/fast/.gitignore
vendored
Normal file
3
tools/fast/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
fast
|
||||
v2
|
||||
index.html
|
@ -56,9 +56,11 @@ 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()
|
||||
}
|
||||
|
||||
@ -78,5 +80,3 @@ fn measure(cmd string) int {
|
||||
exec(cmd)
|
||||
return int(time.ticks() - ticks)
|
||||
}
|
||||
|
||||
|
||||
|
4
tools/fast/footer.html
Normal file
4
tools/fast/footer.html
Normal file
@ -0,0 +1,4 @@
|
||||
</table>
|
||||
<script src="main.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -1,5 +1,8 @@
|
||||
<!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 {
|
||||
@ -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
Normal file
68
tools/fast/main.js
Normal 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;
|
||||
}
|
||||
})();
|
Loading…
Reference in New Issue
Block a user