From 79c9677999b5b2ef1f711bf812bb394037d77a72 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Fri, 6 Dec 2024 08:20:19 +0200 Subject: [PATCH] feat(aoc2024): Add Macro_TimeExecution --- visp/examples/aoc2024/common.visp | 12 ++++++++++++ visp/examples/aoc2024/day6.visp | 5 ++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/visp/examples/aoc2024/common.visp b/visp/examples/aoc2024/common.visp index 70d4ed9..492750f 100644 --- a/visp/examples/aoc2024/common.visp +++ b/visp/examples/aoc2024/common.visp @@ -58,3 +58,15 @@ (begin (ignore (.MoveNext enu)) (+Current enu))]) + +(syntax-macro Macro_TimeExecution + [(_ op body ...) + (begin + (let sw (.StartNew System.Diagnostics.Stopwatch)) + + (let result (begin body ...)) + + (.Stop sw) + (printfn "%s took %fms" op (->> sw +Elapsed +TotalMilliseconds)) + + result)]) diff --git a/visp/examples/aoc2024/day6.visp b/visp/examples/aoc2024/day6.visp index 307138d..96d2ab2 100644 --- a/visp/examples/aoc2024/day6.visp +++ b/visp/examples/aoc2024/day6.visp @@ -102,7 +102,6 @@ (unless (Add_Visited pos dir) (set! result true) (set! looping false)) - ;; (up! visited (Set.add (pos . dir))) ] [_ (match (Grid_Get next grid) @@ -137,7 +136,7 @@ (let PART1_EXPECTED_RESULT (if IS_EXAMPLE 41 5404)) (let PART2_EXPECTED_RESULT (if IS_EXAMPLE 6 1984)) -(WriteResult "part1" (-> parsed Part1) PART1_EXPECTED_RESULT) -(WriteResult "part2" (-> parsed Part2) PART2_EXPECTED_RESULT) +(WriteResult "part1" (Macro_TimeExecution "part1" (-> parsed Part1)) PART1_EXPECTED_RESULT) +(WriteResult "part2" (Macro_TimeExecution "part2" (-> parsed Part2)) PART2_EXPECTED_RESULT) ()