tools/fast: add "V lines" and "V lines/s"

pull/9944/head
Alexander Medvednikov 2021-04-30 15:31:20 +03:00
parent d236d6a473
commit e949d4b26c
6 changed files with 26 additions and 11 deletions

View File

@ -38,6 +38,7 @@ fn main() {
// exec('git checkout $commit')
println(' Building vprod...')
exec('v -o $vdir/vprod -prod $vdir/cmd/v')
// exec('v -o $vdir/vprod $vdir/cmd/v') // for faster debugging
diff1 := measure('$vdir/vprod -cc clang -o v.c -show-timings $vdir/cmd/v', 'v.c')
mut tcc_path := 'tcc'
$if freebsd {
@ -48,7 +49,7 @@ fn main() {
diff4 := measure('$vdir/vprod -cc clang $vdir/examples/hello_world.v', 'hello.v')
vc_size := os.file_size('v.c') / 1000
// scan/parse/check/cgen
scan, parse, check, cgen := measure_steps(vdir)
scan, parse, check, cgen, vlines := 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())
@ -69,6 +70,8 @@ fn main() {
<td>${check}ms</td>
<td>${cgen}ms</td>
<td>${scan}ms</td>
<td>$vlines</td>
<td>${int(f64(vlines) / f64(diff1) * 1000.0)} lines/s</td>
</tr>\n' +
table.trim_space()
out.writeln(table) ?
@ -116,9 +119,10 @@ fn measure(cmd string, description string) int {
return int(sum / 3)
}
fn measure_steps(vdir string) (int, int, int, int) {
resp := os.execute_or_panic('$vdir/vprod -o v.c -show-timings $vdir/cmd/v')
mut scan, mut parse, mut check, mut cgen := 0, 0, 0, 0
fn measure_steps(vdir string) (int, int, int, int, int) {
resp := os.execute_or_panic('$vdir/vprod -o v.c -show-timings -stats $vdir/cmd/v')
mut scan, mut parse, mut check, mut cgen, mut vlines := 0, 0, 0, 0, 0
lines := resp.output.split_into_lines()
if lines.len == 3 {
parse = lines[0].before('.').int()
@ -140,8 +144,16 @@ fn measure_steps(vdir string) (int, int, int, int) {
if line[1] == 'C GEN' {
cgen = line[0].int()
}
} else {
// Fetch number of V lines
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()
}
}
}
return scan, parse, check, cgen
}
return scan, parse, check, cgen, vlines
}

View File

@ -60,4 +60,6 @@ Source code: <a target=blank href='https://github.com/vlang/v/blob/master/cmd/to
<td style='width:55px'>check</td>
<td style='width:55px'>cgen</td>
<td style='width:55px'>scan</td>
<td style='width:55px'>V lines</td>
<td style='width:55px'>V lines/s</td>
</tr>

View File

@ -551,8 +551,8 @@ pub struct File {
pub:
path string // absolute path of the source file - '/projects/v/file.v'
path_base string // file name - 'file.v' (useful for tracing)
lines int // number of source code lines in the file (including newlines and comments)
bytes int // number of processed source code bytes
nr_lines int // number of source code lines in the file (including newlines and comments)
nr_bytes int // number of processed source code bytes
mod Module // the module of the source file (from `module xyz` at the top)
global_scope &Scope
is_test bool // true for _test.v files

View File

@ -49,8 +49,8 @@ pub fn compile(command string, pref &pref.Preferences) {
scompilation_time_ms := util.bold('${f64(compilation_time_micros) / 1000.0:6.3f}')
mut all_v_source_lines, mut all_v_source_bytes := 0, 0
for mut pf in b.parsed_files {
all_v_source_lines += pf.lines
all_v_source_bytes += pf.bytes
all_v_source_lines += pf.nr_lines
all_v_source_bytes += pf.nr_bytes
}
mut sall_v_source_lines := all_v_source_lines.str()
mut sall_v_source_bytes := all_v_source_bytes.str()

View File

@ -1959,6 +1959,7 @@ fn (mut c Checker) array_builtin_method_call(mut call_expr ast.CallExpr, left_ty
} else if method_name == 'sort' {
call_expr.return_type = ast.void_type
} else if method_name == 'contains' {
// c.warn('use `value in arr` instead of `arr.contains(value)`', call_expr.pos)
call_expr.return_type = ast.bool_type
} else if method_name == 'index' {
call_expr.return_type = ast.int_type

View File

@ -283,8 +283,8 @@ pub fn (mut p Parser) parse() ast.File {
path: p.file_name
path_base: p.file_base
is_test: p.inside_test_file
lines: p.scanner.line_nr
bytes: p.scanner.text.len
nr_lines: p.scanner.line_nr
nr_bytes: p.scanner.text.len
mod: module_decl
imports: p.ast_imports
imported_symbols: p.imported_symbols