From e949d4b26cdad5b185e1f20c44399ee39ca71324 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 30 Apr 2021 15:31:20 +0300 Subject: [PATCH] tools/fast: add "V lines" and "V lines/s" --- cmd/tools/fast/fast.v | 22 +++++++++++++++++----- cmd/tools/fast/header.html | 2 ++ vlib/v/ast/ast.v | 4 ++-- vlib/v/builder/compile.v | 4 ++-- vlib/v/checker/checker.v | 1 + vlib/v/parser/parser.v | 4 ++-- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/cmd/tools/fast/fast.v b/cmd/tools/fast/fast.v index 549c15594b..e903daf1ef 100644 --- a/cmd/tools/fast/fast.v +++ b/cmd/tools/fast/fast.v @@ -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() { ${check}ms ${cgen}ms ${scan}ms + $vlines + ${int(f64(vlines) / f64(diff1) * 1000.0)} lines/s \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 } diff --git a/cmd/tools/fast/header.html b/cmd/tools/fast/header.html index 8ff769b7bd..c8bba5f6fa 100644 --- a/cmd/tools/fast/header.html +++ b/cmd/tools/fast/header.html @@ -60,4 +60,6 @@ Source code: check cgen scan + V lines + V lines/s diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 4502206271..6d4f9dd74e 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -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 diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index a2329d70df..811fd2e356 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -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() diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 21d0f2466a..03ce3c33e5 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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 diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 15d0cd6340..df58bfda80 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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