;;; bench-gc-memory.lsp — sustained allocation workload that exposes
;;; the bump-only tier's unbounded growth vs the naive GC tier's
;;; bounded steady-state. The body builds a throwaway list of K pairs
;;; and sums it, repeated N times. Each iteration's list is
;;; unreachable after the sum, so a collecting heap stays flat while
;;; a bump-only heap grows linearly.
;;;
;;; Wall-clock timing is reported from inside; peak RSS is sampled
;;; by the wrapper (tests/bench-gc-memory.sh).

(define K 200)
(define N 2000)

(define (build-list k acc)
  (if (= k 0) acc (build-list (- k 1) (cons k acc))))

(define (sum-list lst acc)
  (if (null? lst) acc (sum-list (cdr lst) (+ acc (car lst)))))

(define total 0)
(define i 0)

(define (step)
  (if (>= i N) total
      (begin
        (set! total (+ total (sum-list (build-list K '()) 0)))
        (set! i (+ i 1))
        (step))))

(define t0 (current-time-ms))
(display "workload N=") (display N) (display " K=") (display K) (newline)
(display "checksum=") (display (step)) (newline)
(display "time_ms=") (display (- (current-time-ms) t0)) (newline)
