#!/usr/bin/env -S v run // Compare only the language subset shared by both runtimes. import os import strconv import time fn main() { if os.args.len > 3 { panic('Usage: v run bench/compare_runtime.vsh [samples=9] [blip_path=~/git/blip]') } 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') } blip_path := os.real_path(os.expand_tilde_to_home(if os.args.len > 2 { os.args[2] } else { '~/git/blip' })) if !os.is_file(os.join_path(blip_path, 'vlib', 'blip', 'machine', 'mod.v')) { panic('Blip runtime not found: ${blip_path}') } compare(blip_path, samples) or { panic(err) } } fn compare(blip_path string, samples int) ! { root := @VMODROOT benchmark_dir := os.join_path(os.temp_dir(), 'vile-vs-blip-${os.getpid()}-${time.sys_mono_now()}') os.mkdir(benchmark_dir)! defer { os.rmdir_all(benchmark_dir) or { eprintln('could not remove ${benchmark_dir}: ${err}') } } binary := os.join_path(benchmark_dir, 'compare_blip' + $if windows { '.exe' } $else { '' }) module_path := '${root}|${os.join_path(blip_path, 'vlib')}|@vlib|@vmodules' mode := '-prod' version := os.exec([@VEXE, 'version']) if version.exit_code != 0 { return error(version.output) } println('Compiler: ${version.output.trim_space()}') println('Flags: -cc gcc ${mode}') println('Blip source: ${blip_path}') revision := os.exec(['git', '-C', blip_path, 'rev-parse', '--short', 'HEAD']) if revision.exit_code == 0 { println('Blip HEAD: ${revision.output.trim_space()} (uses working-tree source)') } println('Building comparison...') // Blip requires V3 module resolution; refuse a fallback to another backend. os.setenv('V_MACOS_V3_NO_FALLBACK', '1', true) mut command := [@VEXE, '-cc', 'gcc'] command << '-prod' command << ['-path', module_path, '-o', binary, os.join_path(root, 'bench', 'runtime')] built := os.exec(command) if built.exit_code != 0 { return error(built.output) } result := os.exec([binary, samples.str()]) print(result.output) if result.exit_code != 0 { return error('comparison exited with status ${result.exit_code}') } }