module main import os import scheme import strconv import time import blip.host import blip.machine struct Timing { elapsed u64 result i64 } fn measure_vile(c RuntimeCase, stage string) !Timing { mut vm := scheme.new_with_options(scheme.Options{ max_steps: 100000000, max_frames: 1000000 })! if stage == 'call' { vm.eval(c.definitions)! proc := vm.lookup('benchmark')! // Clear garbage before the clock; allocation and GC during execution count. gc_collect() start := time.sys_mono_now() result := vm.call(proc, [])! elapsed := time.sys_mono_now() - start return Timing{elapsed, result.as_integer()!} } source := c.definitions + ' (benchmark)' gc_collect() start := time.sys_mono_now() result := vm.eval(source)! elapsed := time.sys_mono_now() - start return Timing{elapsed, result.as_integer()!} } fn measure_blip(c RuntimeCase, stage string) !Timing { mut vm := machine.new_standalone(host.new_capture()) vm.max_steps = 100000000 vm.max_kont = 1000000 if stage == 'call' { proc := vm.run_str(c.definitions + ' benchmark')! gc_collect() start := time.sys_mono_now() result := vm.call_value(proc, [])! elapsed := time.sys_mono_now() - start return Timing{elapsed, result.as_int()!} } source := c.definitions + ' (benchmark)' gc_collect() start := time.sys_mono_now() result := vm.run_str(source)! elapsed := time.sys_mono_now() - start return Timing{elapsed, result.as_int()!} } fn verify(c RuntimeCase, vile Timing, blip Timing) ! { // Explicit checks also run under -prod, which strips V assertions. if vile.result != c.expected || blip.result != c.expected { return error('${c.name}: expected ${c.expected}, got Vile ${vile.result}, Blip ${blip.result}') } } fn median(mut times []u64) f64 { times.sort() mid := times.len / 2 if times.len % 2 == 0 { return (f64(times[mid - 1]) + f64(times[mid])) / 2 } return f64(times[mid]) } fn run_case(c RuntimeCase, stage string, samples int) ! { verify(c, measure_vile(c, stage)!, measure_blip(c, stage)!)! mut vile_times := []u64{len: samples} mut blip_times := []u64{len: samples} for i in 0 .. samples { mut vile := Timing{} mut blip := Timing{} if i % 2 == 0 { vile = measure_vile(c, stage)! blip = measure_blip(c, stage)! } else { blip = measure_blip(c, stage)! vile = measure_vile(c, stage)! } verify(c, vile, blip)! vile_times[i] = vile.elapsed blip_times[i] = blip.elapsed } v := median(mut vile_times) / 1e6 b := median(mut blip_times) / 1e6 println('${c.name:15} ${stage:5} ${v:12.3f} ${b:12.3f} ${b / v:12.2f}') } fn main() { samples := strconv.atoi(if os.args.len > 1 { os.args[1] } else { '9' }) or { panic(err) } if samples < 1 || samples > 101 { panic('samples must be between 1 and 101') } println('Identical source and verified integer results; no prelude or I/O.') println('call: direct host call after definitions; eval: parse + definitions + call.') println('Fresh VM per sample; VM creation excluded; GC before timing; GC during execution included.') println('One warmup per implementation/stage; ${samples} samples, alternating order; medians.') println('case stage Vile ms Blip ms Blip/Vile') for c in runtime_cases() { for stage in ['call', 'eval'] { run_case(c, stage, samples) or { panic(err) } } } }