2022-01-04 12:21:08 +03:00
|
|
|
// Copyright (c) 2019-2022 Alexander Medvednikov. All rights reserved.
|
2019-11-07 20:38:27 +03:00
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
2020-04-26 09:32:05 +03:00
|
|
|
import os
|
|
|
|
import time
|
2022-11-02 11:39:18 +03:00
|
|
|
import arrays
|
|
|
|
|
|
|
|
const warmup_samples = 2
|
|
|
|
|
|
|
|
const max_samples = 10
|
|
|
|
|
|
|
|
const discard_highest_samples = 6
|
2019-11-07 20:38:27 +03:00
|
|
|
|
2022-08-21 10:40:27 +03:00
|
|
|
const voptions = ' -skip-unused -show-timings -stats '
|
2021-05-09 15:14:06 +03:00
|
|
|
|
2022-11-02 11:39:18 +03:00
|
|
|
const fast_dir = os.dir(@FILE)
|
2021-06-12 18:17:29 +03:00
|
|
|
|
2023-01-11 21:34:31 +03:00
|
|
|
const fast_log_path = os.join_path(fast_dir, 'fast.log')
|
|
|
|
|
2022-11-02 11:39:18 +03:00
|
|
|
const vdir = os.dir(os.dir(os.dir(fast_dir)))
|
2021-06-12 18:17:29 +03:00
|
|
|
|
2022-11-02 11:39:18 +03:00
|
|
|
fn elog(msg string) {
|
2023-01-11 21:34:31 +03:00
|
|
|
line := '${time.now().format_ss_micro()} ${msg}\n'
|
|
|
|
if mut f := os.open_append(fast_log_path) {
|
|
|
|
f.write_string(line) or {}
|
|
|
|
f.close()
|
|
|
|
}
|
|
|
|
eprint(line)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn lsystem(cmd string) int {
|
|
|
|
elog('lsystem: ${cmd}')
|
|
|
|
return os.system(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn lexec(cmd string) string {
|
|
|
|
elog(' lexec: ${cmd}')
|
|
|
|
return os.execute_or_exit(cmd).output.trim_right('\r\n')
|
2022-11-02 11:39:18 +03:00
|
|
|
}
|
2021-06-12 18:17:29 +03:00
|
|
|
|
2019-11-07 20:38:27 +03:00
|
|
|
fn main() {
|
2022-11-02 11:39:18 +03:00
|
|
|
total_sw := time.new_stopwatch()
|
|
|
|
elog('fast.html generator start')
|
|
|
|
defer {
|
|
|
|
elog('fast.html generator end, total: ${total_sw.elapsed().milliseconds():6} ms')
|
|
|
|
}
|
|
|
|
//
|
|
|
|
mut ccompiler_path := 'tcc'
|
|
|
|
if vdir.contains('/tmp/cirrus-ci-build') {
|
|
|
|
ccompiler_path = 'clang'
|
|
|
|
}
|
|
|
|
if os.args.contains('-clang') {
|
|
|
|
ccompiler_path = 'clang'
|
|
|
|
}
|
2022-11-15 16:53:13 +03:00
|
|
|
elog('fast_dir: ${fast_dir} | vdir: ${vdir} | compiler: ${ccompiler_path}')
|
2022-11-02 11:39:18 +03:00
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
os.chdir(fast_dir)!
|
2022-11-15 16:53:13 +03:00
|
|
|
if !os.exists('${vdir}/v') && !os.is_dir('${vdir}/vlib') {
|
2022-11-02 11:39:18 +03:00
|
|
|
elog('fast.html generator needs to be located in `v/cmd/tools/fast`')
|
|
|
|
exit(1)
|
2019-12-16 22:22:04 +03:00
|
|
|
}
|
2022-11-02 11:39:18 +03:00
|
|
|
if !os.exists('table.html') {
|
|
|
|
os.create('table.html')!
|
|
|
|
}
|
|
|
|
|
2021-09-28 10:28:04 +03:00
|
|
|
if !os.args.contains('-noupdate') {
|
2022-11-02 11:39:18 +03:00
|
|
|
elog('Fetching updates...')
|
2023-01-11 21:34:31 +03:00
|
|
|
ret := lsystem('${vdir}/v up')
|
2021-09-28 10:28:04 +03:00
|
|
|
if ret != 0 {
|
2022-11-15 16:53:13 +03:00
|
|
|
elog('failed to update V, exit_code: ${ret}')
|
2021-09-28 10:28:04 +03:00
|
|
|
return
|
|
|
|
}
|
2019-12-16 22:22:04 +03:00
|
|
|
}
|
2022-04-21 10:46:35 +03:00
|
|
|
|
|
|
|
// fetch the last commit's hash
|
2023-01-11 21:34:31 +03:00
|
|
|
commit := lexec('git rev-parse HEAD')[..8]
|
2021-08-16 08:26:50 +03:00
|
|
|
if os.exists('website/index.html') {
|
2022-10-16 09:28:57 +03:00
|
|
|
uploaded_index := os.read_file('website/index.html')!
|
2022-11-15 16:53:13 +03:00
|
|
|
if uploaded_index.contains('>${commit}<') {
|
|
|
|
elog('NOTE: commit ${commit} had been benchmarked already.')
|
2022-11-02 11:39:18 +03:00
|
|
|
if !os.args.contains('-force') {
|
|
|
|
elog('nothing more to do')
|
|
|
|
return
|
|
|
|
}
|
2021-08-16 08:26:50 +03:00
|
|
|
}
|
2021-02-07 00:28:42 +03:00
|
|
|
}
|
2022-11-02 11:39:18 +03:00
|
|
|
|
|
|
|
os.chdir(vdir)!
|
2023-01-11 21:34:31 +03:00
|
|
|
message := lexec('git log --pretty=format:"%s" -n1 ${commit}')
|
|
|
|
commit_date := lexec('git log -n1 --pretty="format:%at" ${commit}')
|
2022-11-02 11:39:18 +03:00
|
|
|
date := time.unix(commit_date.i64())
|
|
|
|
|
2022-11-15 16:53:13 +03:00
|
|
|
elog('Benchmarking commit ${commit} , with commit message: "${message}", commit_date: ${commit_date}, date: ${date}')
|
2022-04-21 10:46:35 +03:00
|
|
|
|
|
|
|
// build an optimized V
|
2022-11-02 11:39:18 +03:00
|
|
|
if os.args.contains('-do-not-rebuild-vprod') {
|
|
|
|
if !os.exists('vprod') {
|
2022-11-15 16:53:13 +03:00
|
|
|
elog('Exiting, since if you use `-do-not-rebuild-vprod`, you should already have a `${vdir}/vprod` executable, but it is missing!')
|
2022-11-02 11:39:18 +03:00
|
|
|
return
|
|
|
|
}
|
2021-08-15 09:03:14 +03:00
|
|
|
} else {
|
2022-11-02 11:39:18 +03:00
|
|
|
elog(' Building vprod...')
|
|
|
|
if os.args.contains('-noprod') {
|
2023-01-11 21:34:31 +03:00
|
|
|
lexec('./v -o vprod cmd/v') // for faster debugging
|
2022-11-02 11:39:18 +03:00
|
|
|
} else {
|
2023-01-11 21:34:31 +03:00
|
|
|
lexec('./v -o vprod -prod -prealloc cmd/v')
|
2022-11-02 11:39:18 +03:00
|
|
|
}
|
2021-08-15 09:03:14 +03:00
|
|
|
}
|
2022-04-21 10:46:35 +03:00
|
|
|
|
2022-11-02 11:39:18 +03:00
|
|
|
if !os.args.contains('-do-not-rebuild-caches') {
|
|
|
|
elog('clearing caches...')
|
|
|
|
// cache vlib modules
|
2023-01-11 21:34:31 +03:00
|
|
|
lexec('${vdir}/v wipe-cache')
|
|
|
|
lexec('${vdir}/v -o vwarm_caches -cc ${ccompiler_path} cmd/v')
|
2022-11-02 11:39:18 +03:00
|
|
|
}
|
2022-04-21 10:46:35 +03:00
|
|
|
|
2021-05-24 12:12:14 +03:00
|
|
|
// measure
|
2022-11-15 16:53:13 +03:00
|
|
|
diff1 := measure('${vdir}/vprod ${voptions} -o v.c cmd/v', 'v.c')
|
|
|
|
diff2 := measure('${vdir}/vprod ${voptions} -cc ${ccompiler_path} -o v2 cmd/v', 'v2')
|
2021-04-26 16:39:38 +03:00
|
|
|
diff3 := 0 // measure('$vdir/vprod -native $vdir/cmd/tools/1mil.v', 'native 1mil')
|
2022-11-15 16:53:13 +03:00
|
|
|
diff4 := measure('${vdir}/vprod ${voptions} -cc ${ccompiler_path} examples/hello_world.v',
|
2021-05-26 09:49:22 +03:00
|
|
|
'hello.v')
|
2021-02-07 07:11:48 +03:00
|
|
|
vc_size := os.file_size('v.c') / 1000
|
2022-11-02 11:39:18 +03:00
|
|
|
scan, parse, check, cgen, vlines := measure_steps_minimal(vdir)!
|
2022-04-21 10:46:35 +03:00
|
|
|
|
2022-11-02 11:39:18 +03:00
|
|
|
html_message := message.replace_each(['<', '<', '>', '>'])
|
2022-04-21 10:46:35 +03:00
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
os.chdir(fast_dir)!
|
2022-04-21 10:46:35 +03:00
|
|
|
// place the new row on top
|
2022-11-02 11:39:18 +03:00
|
|
|
table := os.read_file('table.html')!
|
|
|
|
new_table :=
|
2022-04-21 10:46:35 +03:00
|
|
|
' <tr>
|
2022-11-15 16:53:13 +03:00
|
|
|
<td>${date.format()}</td>
|
|
|
|
<td><a target=_blank href="https://github.com/vlang/v/commit/${commit}">${commit}</a></td>
|
|
|
|
<td>${html_message}</td>
|
2020-07-10 17:51:16 +03:00
|
|
|
<td>${diff1}ms</td>
|
|
|
|
<td>${diff2}ms</td>
|
|
|
|
<td>${diff3}ms</td>
|
|
|
|
<td>${diff4}ms</td>
|
2022-11-15 16:53:13 +03:00
|
|
|
<td>${vc_size} KB</td>
|
2021-02-07 06:48:54 +03:00
|
|
|
<td>${parse}ms</td>
|
|
|
|
<td>${check}ms</td>
|
|
|
|
<td>${cgen}ms</td>
|
2021-04-02 20:53:01 +03:00
|
|
|
<td>${scan}ms</td>
|
2022-11-15 16:53:13 +03:00
|
|
|
<td>${vlines}</td>
|
2021-06-06 09:52:29 +03:00
|
|
|
<td>${int(f64(vlines) / f64(diff1) * 1000.0)}</td>
|
2020-07-10 17:51:16 +03:00
|
|
|
</tr>\n' +
|
2022-11-02 11:39:18 +03:00
|
|
|
table.trim_space() + '\n'
|
|
|
|
os.write_file('table.html', new_table)!
|
2022-04-21 10:46:35 +03:00
|
|
|
|
|
|
|
// regenerate index.html
|
2022-10-16 09:28:57 +03:00
|
|
|
header := os.read_file('header.html')!
|
|
|
|
footer := os.read_file('footer.html')!
|
|
|
|
mut res := os.create('index.html')!
|
|
|
|
res.writeln(header)!
|
2022-11-02 11:39:18 +03:00
|
|
|
res.writeln(new_table)!
|
2022-10-16 09:28:57 +03:00
|
|
|
res.writeln(footer)!
|
2021-02-07 07:11:48 +03:00
|
|
|
res.close()
|
2022-04-21 10:46:35 +03:00
|
|
|
|
|
|
|
// upload the result to github pages
|
2021-08-16 08:33:53 +03:00
|
|
|
if os.args.contains('-upload') {
|
2022-11-02 11:39:18 +03:00
|
|
|
elog('uploading...')
|
2022-10-16 09:28:57 +03:00
|
|
|
os.chdir('website')!
|
2023-01-11 21:34:31 +03:00
|
|
|
lexec('git checkout gh-pages')
|
2022-11-02 11:39:18 +03:00
|
|
|
os.mv('../index.html', 'index.html')!
|
2023-01-11 21:34:31 +03:00
|
|
|
lsystem('git commit -am "update benchmark"')
|
|
|
|
lsystem('git push origin gh-pages')
|
2022-11-02 11:39:18 +03:00
|
|
|
elog('uploading done')
|
2021-08-15 09:21:57 +03:00
|
|
|
}
|
2019-11-20 17:59:37 +03:00
|
|
|
}
|
2019-11-07 20:38:27 +03:00
|
|
|
|
2022-04-21 10:46:35 +03:00
|
|
|
// measure returns milliseconds
|
2020-10-21 15:24:45 +03:00
|
|
|
fn measure(cmd string, description string) int {
|
2022-11-15 16:53:13 +03:00
|
|
|
elog(' Measuring ${description}, warmups: ${warmup_samples}, samples: ${max_samples}, discard: ${discard_highest_samples}, with cmd: `${cmd}`')
|
2022-11-02 11:39:18 +03:00
|
|
|
for _ in 0 .. warmup_samples {
|
2023-01-11 21:34:31 +03:00
|
|
|
os.execute_or_exit(cmd)
|
2019-12-16 22:22:04 +03:00
|
|
|
}
|
2020-11-30 22:01:11 +03:00
|
|
|
mut runs := []int{}
|
2022-11-02 11:39:18 +03:00
|
|
|
for r in 0 .. max_samples {
|
2021-07-20 11:17:08 +03:00
|
|
|
sw := time.new_stopwatch()
|
2023-01-11 21:34:31 +03:00
|
|
|
os.execute_or_exit(cmd)
|
2022-11-02 11:39:18 +03:00
|
|
|
sample := int(sw.elapsed().milliseconds())
|
|
|
|
runs << sample
|
2023-01-11 21:34:31 +03:00
|
|
|
elog(' Sample ${r + 1:2}/${max_samples:2} ... ${sample} ms')
|
2020-11-30 22:01:11 +03:00
|
|
|
}
|
|
|
|
runs.sort()
|
2022-11-15 16:53:13 +03:00
|
|
|
elog(' runs before discarding: ${runs}, avg: ${f64(arrays.sum(runs) or { 0 }) / runs.len:5.2f}')
|
2022-11-02 11:39:18 +03:00
|
|
|
// Discard the highest times, since on AWS, they are caused by random load spikes,
|
|
|
|
// that are unpredictable, add noise and skew the statistics, without adding useful
|
|
|
|
// insights:
|
|
|
|
for _ in 0 .. discard_highest_samples {
|
|
|
|
runs.pop()
|
|
|
|
}
|
2022-11-15 16:53:13 +03:00
|
|
|
elog(' runs after discarding: ${runs}, avg: ${f64(arrays.sum(runs) or { 0 }) / runs.len:5.2f}')
|
2022-11-02 11:39:18 +03:00
|
|
|
return int(f64(arrays.sum(runs) or { 0 }) / runs.len)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn measure_steps_minimal(vdir string) !(int, int, int, int, int) {
|
2022-11-15 16:53:13 +03:00
|
|
|
elog('measure_steps_minimal ${vdir}, samples: ${max_samples}')
|
2022-11-02 11:39:18 +03:00
|
|
|
mut scans, mut parses, mut checks, mut cgens, mut vliness := []int{}, []int{}, []int{}, []int{}, []int{}
|
|
|
|
for i in 0 .. max_samples {
|
2023-01-11 21:34:31 +03:00
|
|
|
scan, parse, check, cgen, vlines, cmd := measure_steps_one_sample(vdir)
|
2022-11-02 11:39:18 +03:00
|
|
|
scans << scan
|
|
|
|
parses << parse
|
|
|
|
checks << check
|
|
|
|
cgens << cgen
|
|
|
|
vliness << vlines
|
2023-01-11 21:34:31 +03:00
|
|
|
elog(' [${i:2}/${max_samples:2}] scan: ${scan} ms, min parse: ${parse} ms, min check: ${check} ms, min cgen: ${cgen} ms, min vlines: ${vlines} ms, cmd: ${cmd}')
|
2020-11-30 22:01:11 +03:00
|
|
|
}
|
2022-11-02 11:39:18 +03:00
|
|
|
scan, parse, check, cgen, vlines := arrays.min(scans)!, arrays.min(parses)!, arrays.min(checks)!, arrays.min(cgens)!, arrays.min(vliness)!
|
2022-11-15 16:53:13 +03:00
|
|
|
elog('measure_steps_minimal => min scan: ${scan} ms, min parse: ${parse} ms, min check: ${check} ms, min cgen: ${cgen} ms, min vlines: ${vlines} ms')
|
2022-11-02 11:39:18 +03:00
|
|
|
return scan, parse, check, cgen, vlines
|
2019-11-20 17:59:37 +03:00
|
|
|
}
|
2021-02-07 06:48:54 +03:00
|
|
|
|
2023-01-11 21:34:31 +03:00
|
|
|
fn measure_steps_one_sample(vdir string) (int, int, int, int, int, string) {
|
|
|
|
cmd := '${vdir}/vprod ${voptions} -o v.c cmd/v'
|
|
|
|
resp := os.execute_or_exit(cmd)
|
2021-04-30 15:31:20 +03:00
|
|
|
|
|
|
|
mut scan, mut parse, mut check, mut cgen, mut vlines := 0, 0, 0, 0, 0
|
2021-02-07 06:48:54 +03:00
|
|
|
lines := resp.output.split_into_lines()
|
2021-04-02 20:23:32 +03:00
|
|
|
if lines.len == 3 {
|
|
|
|
parse = lines[0].before('.').int()
|
|
|
|
check = lines[1].before('.').int()
|
|
|
|
cgen = lines[2].before('.').int()
|
|
|
|
} else {
|
|
|
|
ms_lines := lines.map(it.split(' ms '))
|
|
|
|
for line in ms_lines {
|
|
|
|
if line.len == 2 {
|
2021-04-02 20:53:01 +03:00
|
|
|
if line[1] == 'SCAN' {
|
|
|
|
scan = line[0].int()
|
|
|
|
}
|
2021-04-02 20:23:32 +03:00
|
|
|
if line[1] == 'PARSE' {
|
|
|
|
parse = line[0].int()
|
|
|
|
}
|
|
|
|
if line[1] == 'CHECK' {
|
|
|
|
check = line[0].int()
|
|
|
|
}
|
|
|
|
if line[1] == 'C GEN' {
|
|
|
|
cgen = line[0].int()
|
|
|
|
}
|
2021-04-30 15:31:20 +03:00
|
|
|
} else {
|
2022-04-21 10:46:35 +03:00
|
|
|
// fetch number of V lines
|
2021-04-30 15:31:20 +03:00
|
|
|
if line[0].contains('V') && line[0].contains('source') && line[0].contains('size') {
|
|
|
|
start := line[0].index(':') or { 0 }
|
|
|
|
end := line[0].index('lines,') or { 0 }
|
|
|
|
s := line[0][start + 1..end]
|
|
|
|
vlines = s.trim_space().int()
|
|
|
|
}
|
2021-04-02 20:23:32 +03:00
|
|
|
}
|
|
|
|
}
|
2021-02-07 06:48:54 +03:00
|
|
|
}
|
2023-01-11 21:34:31 +03:00
|
|
|
return scan, parse, check, cgen, vlines, cmd
|
2021-02-07 06:48:54 +03:00
|
|
|
}
|