tools: fix find vlib/ -name "*.vv" | xtime xargs v -g run cmd/tools/measure/parser_speed.v

This commit is contained in:
Delyan Angelov 2023-08-22 15:10:30 +03:00
parent b6c7104d9e
commit f4e9aa8e8b
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
3 changed files with 12 additions and 7 deletions

View file

@ -21,7 +21,7 @@ fn main() {
} }
fn hline() { fn hline() {
println('------------------------------------------------------------------------------------------------------------------------------------') println('---------------------------------------------------------------------------------------------------------------------------------------------------')
} }
fn theader() { fn theader() {
@ -40,6 +40,7 @@ fn process_files(files []string) ! {
mut total_tokens := i64(0) mut total_tokens := i64(0)
mut total_lines := i64(0) mut total_lines := i64(0)
mut total_errors := i64(0) mut total_errors := i64(0)
mut total_files := i64(0)
for f in files { for f in files {
mut table := ast.new_table() mut table := ast.new_table()
if f == '' { if f == '' {
@ -48,6 +49,7 @@ fn process_files(files []string) ! {
if skip_tests && f.ends_with('_test.v') { if skip_tests && f.ends_with('_test.v') {
continue continue
} }
total_files++
// do not measure the scanning, but only the parsing: // do not measure the scanning, but only the parsing:
mut p := new_parser(f, .skip_comments, table, pref_) mut p := new_parser(f, .skip_comments, table, pref_)
/// ///
@ -67,7 +69,7 @@ fn process_files(files []string) ! {
hline() hline()
speed_mb_s := term.colorize(term.bright_yellow, '${(f64(total_bytes) / total_us):6.3f} MB/s') 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') 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)') 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:3} thread(s), ${total_files:5} files.')
} }
fn new_parser(path string, comments_mode scanner.CommentsMode, table &ast.Table, pref_ &pref.Preferences) &parser.Parser { fn new_parser(path string, comments_mode scanner.CommentsMode, table &ast.Table, pref_ &pref.Preferences) &parser.Parser {

View file

@ -18,7 +18,7 @@ fn main() {
} }
fn hline() { fn hline() {
println('-------------------------------------------------------------------------------------------------------------------------------------') println('----------------------------------------------------------------------------------------------------------------------------------------------------')
} }
fn theader() { fn theader() {
@ -37,6 +37,7 @@ fn process_files(files []string) ! {
mut total_tokens := i64(0) mut total_tokens := i64(0)
mut total_lines := i64(0) mut total_lines := i64(0)
mut total_errors := i64(0) mut total_errors := i64(0)
mut total_files := i64(0)
for f in files { for f in files {
if f == '' { if f == '' {
continue continue
@ -44,6 +45,7 @@ fn process_files(files []string) ! {
if skip_tests && f.ends_with('_test.v') { if skip_tests && f.ends_with('_test.v') {
continue continue
} }
total_files++
sw.restart() sw.restart()
s := scanner.new_scanner_file(f, .skip_comments, pref_)! s := scanner.new_scanner_file(f, .skip_comments, pref_)!
f_us := sw.elapsed().microseconds() f_us := sw.elapsed().microseconds()
@ -59,5 +61,5 @@ fn process_files(files []string) ! {
hline() hline()
speed_mb_s := term.colorize(term.bright_yellow, '${(f64(total_bytes) / total_us):6.3f} MB/s') 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') 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)') 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:3} thread(s), ${total_files:5} files.')
} }

View file

@ -11,7 +11,8 @@ import os
fn (mut p Parser) call_expr(language ast.Language, mod string) ast.CallExpr { fn (mut p Parser) call_expr(language ast.Language, mod string) ast.CallExpr {
first_pos := p.tok.pos() first_pos := p.tok.pos()
mut name := if language == .js { p.check_js_name() } else { p.check_name() } mut name := if language == .js { p.check_js_name() } else { p.check_name() }
mut is_static_type_method := language == .v && name[0].is_capital() && p.tok.kind == .dot mut is_static_type_method := language == .v && name.len > 0 && name[0].is_capital()
&& p.tok.kind == .dot
if is_static_type_method { if is_static_type_method {
p.check(.dot) p.check(.dot)
name = name + '__static__' + p.check_name() name = name + '__static__' + p.check_name()
@ -1133,10 +1134,10 @@ fn (mut p Parser) closure_vars() []ast.Param {
if p.table.global_scope.known_global(var_name) { if p.table.global_scope.known_global(var_name) {
p.error_with_pos('no need to capture global variable `${var_name}` in closure', p.error_with_pos('no need to capture global variable `${var_name}` in closure',
p.prev_tok.pos()) p.prev_tok.pos())
continue return []
} }
p.error_with_pos('undefined ident: `${var_name}`', p.prev_tok.pos()) p.error_with_pos('undefined ident: `${var_name}`', p.prev_tok.pos())
continue return []
} }
var.is_used = true var.is_used = true
if is_mut { if is_mut {