Skip to content

Commit

Permalink
Add benchmark with time assertions for recursive tuple/list deconstru…
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Nov 27, 2024
1 parent 235bda6 commit 84ea5a3
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

; Issue Overview:
; Recursive deconstruction of tuples and lists has suboptimal performance. This test benchmarks
; TupleCount, ListCount, BuildList, and BuildTuple functions using a Python module to measure execution time.
; TupleCount, ListCount, BuildList, and BuildTuple functions, asserting that their execution time is less than 1 second.

; Define Python Module for Timing
!(py-module benchmark
Expand Down Expand Up @@ -32,9 +32,10 @@ def my_atoms():
($start (current_time))
($result (TupleCount (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30)))
($end (current_time))
($_ (println! "TupleCount result:" $result))
($time (- $end $start))
)
(assertEqualToResult (< $time 1) (True))
)
(println! "TupleCount time (seconds):" (- $end $start)))

; Example 2: ListCount Benchmark
; -------------------------------
Expand All @@ -48,9 +49,10 @@ def my_atoms():
(Cons 11 (Cons 12 (Cons 13 (Cons 14 (Cons 15 (Cons 16 (Cons 17 (Cons 18 (Cons 19 (Cons 20
(Cons 21 (Cons 22 (Cons 23 (Cons 24 (Cons 25 (Cons 26 (Cons 27 (Cons 28 (Cons 29 (Cons 30 Nil))))))))))))))))))))))))))))))))))
($end (current_time))
($_ (println! "ListCount result:" $result))
($time (- $end $start))
)
(assertEqualToResult (< $time 1) (True))
)
(println! "ListCount time (seconds):" (- $end $start)))

; Example 3: BuildList Benchmark
; -------------------------------
Expand All @@ -63,9 +65,10 @@ def my_atoms():
($start (current_time))
($result (BuildList Nil 30))
($end (current_time))
($_ (println! "BuildList result:" $result))
($time (- $end $start))
)
(assertEqualToResult (< $time 1) (True))
)
(println! "BuildList time (seconds):" (- $end $start)))

; Example 4: BuildTuple Benchmark
; -------------------------------
Expand All @@ -78,10 +81,11 @@ def my_atoms():
($start (current_time))
($result (BuildTuple () 30))
($end (current_time))
($_ (println! "BuildTuple result:" $result))
($time (- $end $start))
)
(assertEqualToResult (< $time 1) (True))
)
(println! "BuildTuple time (seconds):" (- $end $start)))

; Summary:
; - Benchmarks TupleCount, ListCount, BuildList, and BuildTuple functions for 30 elements.
; - Measures execution time using the `current_time` operation from the Python `time` module.
; - Asserts that execution time for each function is less than 1 second.

0 comments on commit 84ea5a3

Please sign in to comment.