diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index cbc37270b9..6591a02868 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -21,6 +21,8 @@ mut: out_name_c string out_name_js string max_nr_errors int = 100 + stats_lines int // size of backend generated source code in lines + stats_bytes int // size of backend generated source code in bytes pub mut: module_search_paths []string parsed_files []ast.File @@ -283,6 +285,9 @@ pub fn (b &Builder) find_module_path(mod string, fpath string) ?string { } fn (b &Builder) show_total_warns_and_errors_stats() { + if b.checker.nr_errors == 0 && b.checker.nr_warnings == 0 && b.checker.nr_notices == 0 { + return + } if b.pref.is_stats { estring := util.bold(b.checker.nr_errors.str()) wstring := util.bold(b.checker.nr_warnings.str()) diff --git a/vlib/v/builder/c.v b/vlib/v/builder/c.v index 6c28cc697f..3f41365ebb 100644 --- a/vlib/v/builder/c.v +++ b/vlib/v/builder/c.v @@ -46,23 +46,8 @@ pub fn (mut b Builder) build_c(v_files []string, out_file string) { f.writeln(output2) or { panic(err) } f.close() if b.pref.is_stats { - 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 - } - mut sall_v_source_lines := all_v_source_lines.str() - mut sall_v_source_bytes := all_v_source_bytes.str() - mut slines := (output2.count('\n') + 1).str() - mut sbytes := output2.len.str() - // - slines = util.bold('${slines:10s}') - sbytes = util.bold('${sbytes:10s}') - sall_v_source_lines = util.bold('${sall_v_source_lines:10s}') - sall_v_source_bytes = util.bold('${sall_v_source_bytes:10s}') - // - println(' V source code size: $sall_v_source_lines lines, $sall_v_source_bytes bytes') - println('generated C source code size: $slines lines, $sbytes bytes') + b.stats_lines = output2.count('\n') + 1 + b.stats_bytes = output2.len } // os.write_file(out_file, b.gen_c(v_files)) } diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index 6d8c5e73e8..05f5e21959 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -45,8 +45,28 @@ pub fn compile(command string, pref &pref.Preferences) { .x64 { b.compile_x64() } } if pref.is_stats { - compilation_time := util.bold(sw.elapsed().milliseconds().str()) - println('compilation took: $compilation_time ms') + compilation_time_micros := 1 + sw.elapsed().microseconds() + 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 + } + mut sall_v_source_lines := all_v_source_lines.str() + mut sall_v_source_bytes := all_v_source_bytes.str() + sall_v_source_lines = util.bold('${sall_v_source_lines:10s}') + sall_v_source_bytes = util.bold('${sall_v_source_bytes:10s}') + println(' V source code size: $sall_v_source_lines lines, $sall_v_source_bytes bytes') + // + mut slines := b.stats_lines.str() + mut sbytes := b.stats_bytes.str() + slines = util.bold('${slines:10s}') + sbytes = util.bold('${sbytes:10s}') + println('generated target code size: $slines lines, $sbytes bytes') + // + vlines_per_second := int(1_000_000.0 * f64(all_v_source_lines) / f64(compilation_time_micros)) + svlines_per_second := util.bold(vlines_per_second.str()) + println('compilation took: $scompilation_time_ms ms, compilation speed: $svlines_per_second vlines/s') } b.exit_on_invalid_syntax() // running does not require the parsers anymore diff --git a/vlib/v/builder/js.v b/vlib/v/builder/js.v index ea5ae26653..f92345fb6d 100644 --- a/vlib/v/builder/js.v +++ b/vlib/v/builder/js.v @@ -36,6 +36,10 @@ pub fn (mut b Builder) build_js(v_files []string, out_file string) { output := b.gen_js(v_files) mut f := os.create(out_file) or { panic(err) } f.writeln(output) or { panic(err) } + if b.pref.is_stats { + b.stats_lines = output.count('\n') + 1 + b.stats_bytes = output.len + } f.close() } diff --git a/vlib/v/builder/x64.v b/vlib/v/builder/x64.v index 4e8accf50a..6e8fb1c817 100644 --- a/vlib/v/builder/x64.v +++ b/vlib/v/builder/x64.v @@ -27,7 +27,7 @@ pub fn (mut b Builder) build_x64(v_files []string, out_file string) { markused.mark_used(mut b.table, b.pref, b.parsed_files) } util.timing_start('x64 GEN') - x64.gen(b.parsed_files, b.table, out_file, b.pref) + b.stats_lines, b.stats_bytes = x64.gen(b.parsed_files, b.table, out_file, b.pref) util.timing_measure('x64 GEN') } diff --git a/vlib/v/gen/x64/elf.v b/vlib/v/gen/x64/elf.v index ff702d297c..b25b1a0c9b 100644 --- a/vlib/v/gen/x64/elf.v +++ b/vlib/v/gen/x64/elf.v @@ -103,5 +103,7 @@ pub fn (mut g Gen) generate_elf_footer() { os.chmod(g.out_name, 0o775) // make it an executable unsafe { f.write_ptr(g.buf.data, g.buf.len) } f.close() - println('\nx64 elf binary has been successfully generated') + if g.pref.is_verbose { + println('\nx64 elf binary has been successfully generated') + } } diff --git a/vlib/v/gen/x64/gen.v b/vlib/v/gen/x64/gen.v index 60563aceb2..ae7e199b71 100644 --- a/vlib/v/gen/x64/gen.v +++ b/vlib/v/gen/x64/gen.v @@ -32,6 +32,7 @@ mut: warnings []errors.Warning syms []Symbol relocs []Reloc + nlines int } // string_addr map[string]i64 @@ -81,7 +82,7 @@ enum Size { _64 } -pub fn gen(files []ast.File, table &ast.Table, out_name string, pref &pref.Preferences) { +pub fn gen(files []ast.File, table &ast.Table, out_name string, pref &pref.Preferences) (int, int) { mut g := Gen{ table: table sect_header_name_pos: 0 @@ -96,6 +97,7 @@ pub fn gen(files []ast.File, table &ast.Table, out_name string, pref &pref.Prefe g.stmts(file.stmts) } g.generate_elf_footer() + return g.nlines, g.buf.len } pub fn (mut g Gen) stmts(stmts []ast.Stmt) { @@ -272,6 +274,7 @@ fn (mut g Gen) jle(addr i64) { } fn (mut g Gen) println(comment string) { + g.nlines++ if !g.pref.is_verbose { return }