vile / bench / compare_runtime.vsh
61 lines · 58 sloc · 2.13 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1#!/usr/bin/env -S v run
2
3// Compare only the language subset shared by both runtimes.
4import os
5import strconv
6import time
7
8fn main() {
9 if os.args.len > 3 {
10 panic('Usage: v run bench/compare_runtime.vsh [samples=9] [blip_path=~/git/blip]')
11 }
12 samples := strconv.atoi(if os.args.len > 1 { os.args[1] } else { '9' }) or { panic(err) }
13 if samples < 1 || samples > 101 { panic('samples must be between 1 and 101') }
14 blip_path := os.real_path(os.expand_tilde_to_home(if os.args.len > 2 {
15 os.args[2]
16 } else {
17 '~/git/blip'
18 }))
19 if !os.is_file(os.join_path(blip_path, 'vlib', 'blip', 'machine', 'mod.v')) {
20 panic('Blip runtime not found: ${blip_path}')
21 }
22 compare(blip_path, samples) or { panic(err) }
23}
24
25fn compare(blip_path string, samples int) ! {
26 root := @VMODROOT
27 benchmark_dir := os.join_path(os.temp_dir(), 'vile-vs-blip-${os.getpid()}-${time.sys_mono_now()}')
28 os.mkdir(benchmark_dir)!
29 defer {
30 os.rmdir_all(benchmark_dir) or { eprintln('could not remove ${benchmark_dir}: ${err}') }
31 }
32 binary := os.join_path(benchmark_dir, 'compare_blip' + $if windows { '.exe' } $else { '' })
33 module_path := '${root}|${os.join_path(blip_path, 'vlib')}|@vlib|@vmodules'
34 mode := '-prod'
35 version := os.exec([@VEXE, 'version'])
36 if version.exit_code != 0 {
37 return error(version.output)
38 }
39 println('Compiler: ${version.output.trim_space()}')
40 println('Flags: -cc gcc ${mode}')
41 println('Blip source: ${blip_path}')
42 revision := os.exec(['git', '-C', blip_path, 'rev-parse', '--short', 'HEAD'])
43 if revision.exit_code == 0 {
44 println('Blip HEAD: ${revision.output.trim_space()} (uses working-tree source)')
45 }
46 println('Building comparison...')
47 // Blip requires V3 module resolution; refuse a fallback to another backend.
48 os.setenv('V_MACOS_V3_NO_FALLBACK', '1', true)
49 mut command := [@VEXE, '-cc', 'gcc']
50 command << '-prod'
51 command << ['-path', module_path, '-o', binary, os.join_path(root, 'bench', 'runtime')]
52 built := os.exec(command)
53 if built.exit_code != 0 {
54 return error(built.output)
55 }
56 result := os.exec([binary, samples.str()])
57 print(result.output)
58 if result.exit_code != 0 {
59 return error('comparison exited with status ${result.exit_code}')
60 }
61}
62