module main import scheme // Allocation counts only: compilation and warm-up happen before measurement. fn main() { $if !gcboehm ? { panic('Build with Boehm GC to inspect allocation totals.') } println('case iterations allocated bytes') for expression in ['(current-jiffy)', '(current-second)', '(jiffies-per-second)'] { mut vm := scheme.new_with_options(scheme.Options{ max_steps: 0, max_frames: 24 }) or { panic(err) } procedure := vm.eval('(lambda (n) (let loop ((i n)) (if (= i 0) 42 (begin ${expression} (loop (- i 1))))))') or { panic(err) } vm.call(procedure, [scheme.integer(100)]) or { panic(err) } for count in [1000, 100000, 1000000] { args := [scheme.integer(count)] gc_collect() before := gc_heap_usage().total_bytes result := vm.call(procedure, args) or { panic(err) } allocated := gc_heap_usage().total_bytes - before if result.as_integer() or { panic(err) } != 42 { panic('incorrect loop result') } println('${expression:24} ${count:10} ${allocated:20}') } } }