Added runtime measurement

master
Mark 2022-10-28 19:05:38 -07:00
parent 6e46f485c1
commit 393e52327e
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
2 changed files with 20 additions and 26 deletions

View File

@ -5,7 +5,6 @@
- $\alpha$-equivalence check - $\alpha$-equivalence check
- Prettyprint functions (rename bound variables) - Prettyprint functions (rename bound variables)
- Write a nice README - Write a nice README
- Handle or avoid recursion errors
- Fix colors - Fix colors
- Print macro content if only a macro is typed - Print macro content if only a macro is typed

View File

@ -4,6 +4,7 @@ from prompt_toolkit import print_formatted_text as printf
from prompt_toolkit.shortcuts import clear as clear_screen from prompt_toolkit.shortcuts import clear as clear_screen
import enum import enum
import math import math
import time
import lamb import lamb
@ -105,6 +106,7 @@ class Runner:
macro_expansions = 0 macro_expansions = 0
stop_reason = StopReason.MAX_EXCEEDED stop_reason = StopReason.MAX_EXCEEDED
start_time = time.time()
while (self.reduction_limit is None) or (i < self.reduction_limit): while (self.reduction_limit is None) or (i < self.reduction_limit):
@ -138,13 +140,10 @@ class Runner:
# Clear reduction counter # Clear reduction counter
print(" " * round(14 + math.log10(i)), end = "\r") print(" " * round(14 + math.log10(i)), end = "\r")
if ( out_text = [
stop_reason == StopReason.BETA_NORMAL or ("class:result_header", f"\nRuntime: "),
stop_reason == StopReason.LOOP_DETECTED ("class:text", f"{time.time() - start_time:.03f} seconds"),
):
out_str = str(new_node) # type: ignore
printf(FormattedText([
("class:result_header", f"\nExit reason: "), ("class:result_header", f"\nExit reason: "),
stop_reason.value, stop_reason.value,
@ -152,23 +151,19 @@ class Runner:
("class:text", str(macro_expansions)), ("class:text", str(macro_expansions)),
("class:result_header", f"\nReductions: "), ("class:result_header", f"\nReductions: "),
("class:text", str(i)), ("class:text", str(i))
]
if (stop_reason == StopReason.BETA_NORMAL or stop_reason == StopReason.LOOP_DETECTED):
out_text += [
("class:result_header", "\n\n => "), ("class:result_header", "\n\n => "),
("class:text", out_str), ("class:text", str(new_node)), # type: ignore
]), style = lamb.utils.style) ]
else:
printf(FormattedText([
("class:result_header", f"\nExit reason: "),
stop_reason.value,
("class:result_header", f"\nMacro expansions: "), printf(
("class:text", str(macro_expansions)), FormattedText(out_text),
style = lamb.utils.style
("class:result_header", f"\nReductions: "), )
("class:text", str(i)),
]), style = lamb.utils.style)
def save_macro( def save_macro(
self, self,