From 393e52327e305afa4d5e4a84d49820bc5932f1ed Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 28 Oct 2022 19:05:38 -0700 Subject: [PATCH] Added runtime measurement --- README.md | 1 - lamb/runner.py | 45 ++++++++++++++++++++------------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 4a61fe7..47a2f21 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ - $\alpha$-equivalence check - Prettyprint functions (rename bound variables) - Write a nice README - - Handle or avoid recursion errors - Fix colors - Print macro content if only a macro is typed diff --git a/lamb/runner.py b/lamb/runner.py index 98ccdd6..a5cc3a0 100644 --- a/lamb/runner.py +++ b/lamb/runner.py @@ -4,6 +4,7 @@ from prompt_toolkit import print_formatted_text as printf from prompt_toolkit.shortcuts import clear as clear_screen import enum import math +import time import lamb @@ -105,6 +106,7 @@ class Runner: macro_expansions = 0 stop_reason = StopReason.MAX_EXCEEDED + start_time = time.time() while (self.reduction_limit is None) or (i < self.reduction_limit): @@ -138,37 +140,30 @@ class Runner: # Clear reduction counter print(" " * round(14 + math.log10(i)), end = "\r") - if ( - stop_reason == StopReason.BETA_NORMAL or - stop_reason == StopReason.LOOP_DETECTED - ): - out_str = str(new_node) # type: ignore + out_text = [ + ("class:result_header", f"\nRuntime: "), + ("class:text", f"{time.time() - start_time:.03f} seconds"), - printf(FormattedText([ - ("class:result_header", f"\nExit reason: "), - stop_reason.value, + ("class:result_header", f"\nExit reason: "), + stop_reason.value, - ("class:result_header", f"\nMacro expansions: "), - ("class:text", str(macro_expansions)), - - ("class:result_header", f"\nReductions: "), - ("class:text", str(i)), + ("class:result_header", f"\nMacro expansions: "), + ("class:text", str(macro_expansions)), + ("class:result_header", f"\nReductions: "), + ("class:text", str(i)) + ] + if (stop_reason == StopReason.BETA_NORMAL or stop_reason == StopReason.LOOP_DETECTED): + out_text += [ ("class:result_header", "\n\n => "), - ("class:text", out_str), - ]), style = lamb.utils.style) - else: - printf(FormattedText([ - ("class:result_header", f"\nExit reason: "), - stop_reason.value, + ("class:text", str(new_node)), # type: ignore + ] - ("class:result_header", f"\nMacro expansions: "), - ("class:text", str(macro_expansions)), - - ("class:result_header", f"\nReductions: "), - ("class:text", str(i)), - ]), style = lamb.utils.style) + printf( + FormattedText(out_text), + style = lamb.utils.style + ) def save_macro( self,