mirror of
https://github.com/samsonjs/sectorlisp.git
synced 2026-04-27 14:57:41 +00:00
Add performance counter
This commit is contained in:
parent
334ec21213
commit
0916d58550
1 changed files with 30 additions and 11 deletions
41
lisp.js
41
lisp.js
|
|
@ -406,8 +406,17 @@ function ReadChar() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function GetMillis() {
|
||||||
|
if (typeof performance != "undefined") {
|
||||||
|
return performance.now();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Lisp() {
|
function Lisp() {
|
||||||
var x, A;
|
var x, A, d, t;
|
||||||
|
d = 0;
|
||||||
cGets = 0;
|
cGets = 0;
|
||||||
cSets = 0;
|
cSets = 0;
|
||||||
cHeap = cx;
|
cHeap = cx;
|
||||||
|
|
@ -424,7 +433,9 @@ function Lisp() {
|
||||||
a = Define(0, Cdr(x), a);
|
a = Define(0, Cdr(x), a);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
t = GetMillis();
|
||||||
x = Eval(x, a);
|
x = Eval(x, a);
|
||||||
|
d += GetMillis() - t;
|
||||||
} catch (z) {
|
} catch (z) {
|
||||||
PrintChar(Ord('?'));
|
PrintChar(Ord('?'));
|
||||||
x = z;
|
x = z;
|
||||||
|
|
@ -437,7 +448,7 @@ function Lisp() {
|
||||||
eOutput.innerText = output;
|
eOutput.innerText = output;
|
||||||
SaveMachine(a);
|
SaveMachine(a);
|
||||||
SaveOutput();
|
SaveOutput();
|
||||||
ReportUsage();
|
ReportUsage(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Load(s) {
|
function Load(s) {
|
||||||
|
|
@ -452,7 +463,9 @@ function OnEval() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function OnReset() {
|
function OnReset() {
|
||||||
|
var t;
|
||||||
output = "";
|
output = "";
|
||||||
|
t = GetMillis();
|
||||||
try {
|
try {
|
||||||
Dump(a);
|
Dump(a);
|
||||||
eOutput.innerText = output;
|
eOutput.innerText = output;
|
||||||
|
|
@ -460,9 +473,10 @@ function OnReset() {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
/* ignored */
|
/* ignored */
|
||||||
}
|
}
|
||||||
|
t = GetMillis() - t;
|
||||||
localStorage.removeItem("sectorlisp.machine");
|
localStorage.removeItem("sectorlisp.machine");
|
||||||
SaveOutput();
|
SaveOutput();
|
||||||
ReportUsage();
|
ReportUsage(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
function OnTrace() {
|
function OnTrace() {
|
||||||
|
|
@ -513,22 +527,27 @@ function SaveOutput() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Number(i) {
|
function FormatInt(i) {
|
||||||
return i.toLocaleString();
|
return i.toLocaleString();
|
||||||
}
|
}
|
||||||
|
|
||||||
function ReportUsage() {
|
function FormatDuration(d) {
|
||||||
var i, c;
|
return d ? Math.round(d * 1000) / 1000 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ReportUsage(d) {
|
||||||
|
var i, c, s;
|
||||||
for (c = i = 0; i < Null; i += 2) {
|
for (c = i = 0; i < Null; i += 2) {
|
||||||
if (M[Null + i]) ++c;
|
if (M[Null + i]) ++c;
|
||||||
}
|
}
|
||||||
document.getElementById("ops").innerText =
|
document.getElementById("ops").innerText =
|
||||||
Number(cGets) + " gets / " +
|
FormatInt(cGets) + " gets / " +
|
||||||
Number(cSets) + " sets";
|
FormatInt(cSets) + " sets / " +
|
||||||
|
FormatDuration(d) + " ms";
|
||||||
document.getElementById("mem").innerText =
|
document.getElementById("mem").innerText =
|
||||||
Number((-cx >> 1) + c) + " / " +
|
FormatInt((-cx >> 1) + c) + " / " +
|
||||||
Number((-cHeap >> 1) + c) + " / " +
|
FormatInt((-cHeap >> 1) + c) + " / " +
|
||||||
Number(Null) + " doublewords";
|
FormatInt(Null) + " doublewords";
|
||||||
}
|
}
|
||||||
|
|
||||||
function Discount(f) {
|
function Discount(f) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue