diff --git a/cmd/tools/fast/fast.v b/cmd/tools/fast/fast.v
index 82817d264a..d5d4b1baf4 100644
--- a/cmd/tools/fast/fast.v
+++ b/cmd/tools/fast/fast.v
@@ -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() {
${diff2}ms |
${diff3}ms |
${diff4}ms |
+ $vc_size KB |
+ ${parse}ms |
+ ${check}ms |
+ ${cgen}ms |
\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
+}
diff --git a/cmd/tools/fast/header.html b/cmd/tools/fast/header.html
index d6e60afbac..250e9de348 100644
--- a/cmd/tools/fast/header.html
+++ b/cmd/tools/fast/header.html
@@ -52,4 +52,8 @@ Source code: v -o v
v -x64 1mil.v |
v hello.v |
+ v.c size |
+ parse |
+ check |
+ cgen |
diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v
index 17febaa2f7..4c19b305bd 100644
--- a/vlib/builtin/string.v
+++ b/vlib/builtin/string.v
@@ -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