1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tools/fast: measure v.c size and parse/check/cgen steps

This commit is contained in:
Alexander Medvednikov 2021-02-07 04:48:54 +01:00
parent 32cd2846f5
commit a81ee0e94e
3 changed files with 41 additions and 1 deletions

View File

@ -56,6 +56,10 @@ fn main() {
}
}
println(last_commits)
if commits.len == 0 {
// Just benchmark the last commit if the tool hasn't been run for too long.
// commits = [commit_hash]
}
println('Commits to benchmark:')
println(commits)
for i, commit in commits {
@ -66,10 +70,13 @@ fn main() {
exec('git checkout $commit')
println(' Building vprod...')
exec('v -o $vdir/vprod -prod $vdir/cmd/v')
diff1 := measure('$vdir/vprod -cc clang -o v.c $vdir/cmd/v', 'v.c')
diff1 := measure('$vdir/vprod -cc clang -o v.c -show-timings $vdir/cmd/v', 'v.c')
diff2 := measure('$vdir/vprod -cc clang -o v2 $vdir/cmd/v', 'v2')
diff3 := measure('$vdir/vprod -x64 $vdir/cmd/tools/1mil.v', 'x64 1mil')
diff4 := measure('$vdir/vprod -cc clang $vdir/examples/hello_world.v', 'hello.v')
vc_size := os.file_size('v.c') / 1000
// parse/check/cgen
parse, check, cgen := measure_steps(vdir)
// println('Building V took ${diff}ms')
commit_date := exec('git log -n1 --pretty="format:%at" $commit')
date := time.unix(commit_date.int())
@ -84,6 +91,10 @@ fn main() {
<td>${diff2}ms</td>
<td>${diff3}ms</td>
<td>${diff4}ms</td>
<td>$vc_size KB</td>
<td>${parse}ms</td>
<td>${check}ms</td>
<td>${cgen}ms</td>
</tr>\n' +
table.trim_space()
out.writeln(table) ?
@ -130,3 +141,17 @@ fn measure(cmd string, description string) int {
}
return int(sum / 3)
}
fn measure_steps(vdir string) (int, int, int) {
resp := os.exec('$vdir/vprod -o v.c -show-timings $vdir/cmd/v') or { panic(err) }
println('=======')
println(resp.output)
lines := resp.output.split_into_lines()
if lines.len != 3 {
return 0, 0, 0
}
parse := lines[0].before('.').int()
check := lines[1].before('.').int()
cgen := lines[2].before('.').int()
return parse, check, cgen
}

View File

@ -52,4 +52,8 @@ Source code: <a target=blank href='https://github.com/vlang/v/blob/master/cmd/to
<td style='width:120px'>v -o v</td>
<td style='width:130px'>v -x64 1mil.v</td>
<td style='width:120px'>v hello.v</td>
<td style='width:120px'>v.c size</td>
<td style='width:120px'>parse</td>
<td style='width:120px'>check</td>
<td style='width:120px'>cgen</td>
</tr>

View File

@ -1403,9 +1403,20 @@ pub fn (s &string) free() {
s.is_lit = -98761234
}
// before returns the contents before `dot` in the string.
// Example: assert '23:34:45.234'.all_before('.') == '23:34:45'
pub fn (s string) before(dot string) string {
pos := s.index_(dot)
if pos == -1 {
return s
}
return s[..pos]
}
// all_before returns the contents before `dot` in the string.
// Example: assert '23:34:45.234'.all_before('.') == '23:34:45'
pub fn (s string) all_before(dot string) string {
// TODO remove dup method
pos := s.index_(dot)
if pos == -1 {
return s