vile / bench / system.v
25 lines · 23 sloc · 1.02 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module main
2
3import scheme
4
5// Allocation counts only: compilation and warm-up happen before measurement.
6fn main() {
7 $if !gcboehm ? {
8 panic('Build with Boehm GC to inspect allocation totals.')
9 }
10 println('case iterations allocated bytes')
11 for expression in ['(current-jiffy)', '(current-second)', '(jiffies-per-second)'] {
12 mut vm := scheme.new_with_options(scheme.Options{ max_steps: 0, max_frames: 24 }) or { panic(err) }
13 procedure := vm.eval('(lambda (n) (let loop ((i n)) (if (= i 0) 42 (begin ${expression} (loop (- i 1))))))') or { panic(err) }
14 vm.call(procedure, [scheme.integer(100)]) or { panic(err) }
15 for count in [1000, 100000, 1000000] {
16 args := [scheme.integer(count)]
17 gc_collect()
18 before := gc_heap_usage().total_bytes
19 result := vm.call(procedure, args) or { panic(err) }
20 allocated := gc_heap_usage().total_bytes - before
21 if result.as_integer() or { panic(err) } != 42 { panic('incorrect loop result') }
22 println('${expression:24} ${count:10} ${allocated:20}')
23 }
24 }
25}
26