show stats about how long eval takes, and how long it takes per pixel

This commit is contained in:
profan 2026-06-05 20:12:24 +01:00
parent da83b1857e
commit e47723b3c4
1 changed files with 12 additions and 1 deletions

View File

@ -70,6 +70,8 @@ void Main()
bool shouldCancelUpdateTexture = false; bool shouldCancelUpdateTexture = false;
bool shouldUpdateTexture = false; bool shouldUpdateTexture = false;
float lastEvaluationTimeTook = 0.0f;
while (!Raylib.WindowShouldClose()) while (!Raylib.WindowShouldClose())
{ {
Raylib.BeginDrawing(); Raylib.BeginDrawing();
@ -90,6 +92,7 @@ void Main()
Task.Run(() => Task.Run(() =>
{ {
Stopwatch sw = Stopwatch.StartNew();
Instruction[] instructions = Parsing.Parse(programsProsperoVm); Instruction[] instructions = Parsing.Parse(programsProsperoVm);
currentOutputImageData.AsSpan()[..currentOutputImageData.Length].Clear(); currentOutputImageData.AsSpan()[..currentOutputImageData.Length].Clear();
@ -101,7 +104,8 @@ void Main()
{ {
Interpreter.Evaluate<float>(instructions, imageSize: currentOutputImageSize, interpreterOptions, currentOutputImageData); Interpreter.Evaluate<float>(instructions, imageSize: currentOutputImageSize, interpreterOptions, currentOutputImageData);
} }
lastEvaluationTimeTook = (float)sw.Elapsed.TotalSeconds;
Raylib.UpdateTexture(currentOutputTexture, currentOutputImageData); Raylib.UpdateTexture(currentOutputTexture, currentOutputImageData);
shouldCancelUpdateTexture = true; shouldCancelUpdateTexture = true;
isEvaluating = false; isEvaluating = false;
@ -127,6 +131,13 @@ void Main()
Raylib.DrawText("Sharpero (press R to evaluate, O to output to file)", 12, 12, 20, Color.White); Raylib.DrawText("Sharpero (press R to evaluate, O to output to file)", 12, 12, 20, Color.White);
Raylib.DrawText($" - parallelism {(shouldUseParallelism ? "enabled" : "disabled")} (P to toggle), simd {(shouldUseSimd ? "enabled" : "disabled")} (S to toggle)", 12, 32, 20, Color.White); Raylib.DrawText($" - parallelism {(shouldUseParallelism ? "enabled" : "disabled")} (P to toggle), simd {(shouldUseSimd ? "enabled" : "disabled")} (S to toggle)", 12, 32, 20, Color.White);
if (lastEvaluationTimeTook != 0.0f)
{
double nanoSecondsPerPixel =
(lastEvaluationTimeTook * 1000.0 * 1000.0 * 1000.0) / (currentOutputImageSize * currentOutputImageSize) ;
Raylib.DrawText($" - evaluation took: {lastEvaluationTimeTook:0.0} s ({nanoSecondsPerPixel:0.0} ns / pixel)", 12, 52, 20, Color.White);
}
if (Raylib.IsKeyPressed(KeyboardKey.R)) if (Raylib.IsKeyPressed(KeyboardKey.R))
{ {
shouldEvaluate = true; shouldEvaluate = true;