| 1 | module main |
| 2 | |
| 3 | import scheme |
| 4 | |
| 5 | // Allocation-only comparison for the ordinary acyclic printer. Warm-up and |
| 6 | // source evaluation are excluded; the probe makes no timing claims. |
| 7 | fn main() { |
| 8 | $if !gcboehm ? { |
| 9 | panic('Boehm GC required') |
| 10 | } |
| 11 | for name, source in { |
| 12 | 'literal-list': "'(" + '1 '.repeat(1000) + ')' |
| 13 | 'mutable-list': '(make-list 1000 1)' |
| 14 | 'shared-tree': '(define tail (make-list 100 1)) (make-list 10 tail)' |
| 15 | } { |
| 16 | mut vm := scheme.new() |
| 17 | value := vm.eval(source) or { panic(err) } |
| 18 | original := scheme.write(value) or { panic(err) } |
| 19 | for _ in 0 .. 5 { scheme.write(value) or { panic(err) } } |
| 20 | for count in [1, 10, 100] { |
| 21 | gc_collect() |
| 22 | before := gc_heap_usage().total_bytes |
| 23 | mut checksum := 0 |
| 24 | for _ in 0 .. count { |
| 25 | text := scheme.write(value) or { panic(err) } |
| 26 | checksum += text.len |
| 27 | } |
| 28 | allocated := gc_heap_usage().total_bytes - before |
| 29 | if checksum != original.len * count { panic('invalid printer result') } |
| 30 | println('${name} ${count} ${allocated}') |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |