Skip to content

Commit

Permalink
tools: improve the output of parser_speed.v and scanner_speed.v
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Aug 22, 2023
1 parent 5e0ebba commit 644c68c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
25 changes: 22 additions & 3 deletions cmd/tools/measure/parser_speed.v
Expand Up @@ -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()

Expand All @@ -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
Expand All @@ -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 == '' {
Expand All @@ -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 {
Expand Down
23 changes: 21 additions & 2 deletions cmd/tools/measure/scanner_speed.v
@@ -1,5 +1,6 @@
import os
import time
import term
import v.scanner
import v.pref

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)')
}

0 comments on commit 644c68c

Please sign in to comment.