From 644c68ce944cd857ab146ea55cc675db129230eb Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 22 Aug 2023 14:23:47 +0300 Subject: [PATCH] tools: improve the output of parser_speed.v and scanner_speed.v --- cmd/tools/measure/parser_speed.v | 25 ++++++++++++++++++++++--- cmd/tools/measure/scanner_speed.v | 23 +++++++++++++++++++++-- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/cmd/tools/measure/parser_speed.v b/cmd/tools/measure/parser_speed.v index 88e444910018ab..42d68535df1c99 100644 --- a/cmd/tools/measure/parser_speed.v +++ b/cmd/tools/measure/parser_speed.v @@ -5,6 +5,7 @@ import v.pref import v.parser import v.errors import v.scanner +import term const skip_tests = os.getenv_opt('SKIP_TESTS') or { '' }.bool() @@ -19,7 +20,16 @@ fn main() { process_files(files)! } +fn hline() { + println('------------------------------------------------------------------------------------------------------------------------------------') +} + +fn theader() { + println(' Time Tokens Bytes Lines Bytes/Token Errors') +} + fn process_files(files []string) ! { + nthreads := 1 // TODO mut pref_ := pref.new_preferences() pref_.is_fmt = true pref_.skip_warnings = true @@ -28,6 +38,8 @@ fn process_files(files []string) ! { mut total_us := i64(0) mut total_bytes := i64(0) mut total_tokens := i64(0) + mut total_lines := i64(0) + mut total_errors := i64(0) for f in files { mut table := ast.new_table() if f == '' { @@ -40,15 +52,22 @@ fn process_files(files []string) ! { mut p := new_parser(f, .skip_comments, table, pref_) /// sw.restart() - _ := p.parse() + ast_file := p.parse() f_us := sw.elapsed().microseconds() /// total_us += f_us total_bytes += p.scanner.text.len total_tokens += p.scanner.all_tokens.len - println('${f_us:10}us ${p.scanner.all_tokens.len:10} ${p.scanner.text.len:10} ${(f64(p.scanner.text.len) / p.scanner.all_tokens.len):7.3} ${p.errors.len:4} ${f}') + total_lines += ast_file.nr_lines + total_errors += p.errors.len + println('${f_us:10}us ${p.scanner.all_tokens.len:10} ${p.scanner.text.len:10} ${ast_file.nr_lines:10} ${(f64(p.scanner.text.len) / p.scanner.all_tokens.len):13.3} ${p.errors.len:10} ${f}') } - println('${total_us:10}us ${total_tokens:10} ${total_bytes:10} ${(f64(total_tokens) / total_bytes):7.3} | speed: ${(f64(total_bytes) / total_us):2.5f} MB/s') + hline() + theader() + hline() + speed_mb_s := term.colorize(term.bright_yellow, '${(f64(total_bytes) / total_us):6.3f} MB/s') + speed_lines_s := term.colorize(term.bright_yellow, '${(1_000_000 * f64(total_lines) / total_us):10.1f} lines/s') + println('${total_us:10}us ${total_tokens:10} ${total_bytes:10} ${total_lines:10} ${(f64(total_bytes) / total_tokens):13.3} ${total_errors:10} Parser speed: ${speed_mb_s}, ${speed_lines_s}, ${nthreads} thread(s)') } fn new_parser(path string, comments_mode scanner.CommentsMode, table &ast.Table, pref_ &pref.Preferences) &parser.Parser { diff --git a/cmd/tools/measure/scanner_speed.v b/cmd/tools/measure/scanner_speed.v index e1426e4e6b947d..c3c6a89c2b0da9 100644 --- a/cmd/tools/measure/scanner_speed.v +++ b/cmd/tools/measure/scanner_speed.v @@ -1,5 +1,6 @@ import os import time +import term import v.scanner import v.pref @@ -16,7 +17,16 @@ fn main() { process_files(files)! } +fn hline() { + println('-------------------------------------------------------------------------------------------------------------------------------------') +} + +fn theader() { + println(' Time Tokens Bytes Lines Bytes/Token Errors') +} + fn process_files(files []string) ! { + nthreads := 1 // TODO mut pref_ := pref.new_preferences() pref_.is_fmt = true pref_.skip_warnings = true @@ -25,6 +35,8 @@ fn process_files(files []string) ! { mut total_us := i64(0) mut total_bytes := i64(0) mut total_tokens := i64(0) + mut total_lines := i64(0) + mut total_errors := i64(0) for f in files { if f == '' { continue @@ -38,7 +50,14 @@ fn process_files(files []string) ! { total_us += f_us total_bytes += s.text.len total_tokens += s.all_tokens.len - println('${f_us:10}us ${s.all_tokens.len:10} ${s.text.len:10} ${(f64(s.text.len) / s.all_tokens.len):7.3f} ${f}') + total_lines += s.nr_lines + total_errors += s.errors.len + println('${f_us:10}us ${s.all_tokens.len:10} ${s.text.len:10} ${s.nr_lines:10} ${(f64(s.text.len) / s.all_tokens.len):13.3f} ${s.errors.len:10} ${f}') } - println('${total_us:10}us ${total_tokens:10} ${total_bytes:10} ${(f64(total_tokens) / total_bytes):7.3f} | speed: ${(f64(total_bytes) / total_us):2.5f} MB/s') + hline() + theader() + hline() + speed_mb_s := term.colorize(term.bright_yellow, '${(f64(total_bytes) / total_us):6.3f} MB/s') + speed_lines_s := term.colorize(term.bright_yellow, '${(1_000_000 * f64(total_lines) / total_us):10.1f} lines/s') + println('${total_us:10}us ${total_tokens:10} ${total_bytes:10} ${total_lines:10} ${(f64(total_bytes) / total_tokens):13.3} ${total_errors:10} Scanner speed: ${speed_mb_s}, ${speed_lines_s}, ${nthreads} thread(s)') }