1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: implement -stats option for running a _test.v file

* Draft implementation of `v -stats file_test.v` .

* compiler: call stuff in vlib/benchmark/tests/always_imported.v, when doing `v -stats file_test.v`

* Nicer looking output from 'v -stats file_test.v' .

* Tweak colors and layout of -stats file_test.v .

* Fix a hardcoded path in compiler/main.v .

* Show colorized OK/FAIL for the examples in 'v test v' too.

* Add some comments about the purpose of the methods inside vlib/benchmark/tests/always_imported.v .

* when fails are 0, do not colorize their number at all.
This commit is contained in:
Delyan Angelov
2019-10-07 08:51:26 +03:00
committed by Alexander Medvednikov
parent f1923d454c
commit ac5241b5bd
5 changed files with 181 additions and 20 deletions

View File

@@ -1,6 +1,7 @@
module benchmark
import time
import term
/*
Example usage of this module:
@@ -64,18 +65,40 @@ pub fn (b mut Benchmark) ok() {
b.nok++
}
pub fn (b mut Benchmark) fail_many(n int) {
b.step_end_time = benchmark.now()
b.ntotal+=n
b.nfail+=n
}
pub fn (b mut Benchmark) ok_many(n int) {
b.step_end_time = benchmark.now()
b.ntotal+=n
b.nok+=n
}
pub fn (b mut Benchmark) neither_fail_nor_ok() {
b.step_end_time = benchmark.now()
}
pub fn (b mut Benchmark) step_message(msg string) string {
return b.tdiff_in_ms(msg, b.step_start_time, b.step_end_time)
}
pub fn (b mut Benchmark) total_message(msg string) string {
mut tmsg := '$msg : ok, fail, total = ${b.nok:5d}, ${b.nfail:5d}, ${b.ntotal:5d}'
mut tmsg := '$msg \n ok, fail, total = ' +
term.ok_message('${b.nok:5d}') + ', ' +
if b.nfail > 0 { term.fail_message('${b.nfail:5d}') } else { '${b.nfail:5d}' } + ', ' +
'${b.ntotal:5d}'
if b.verbose {
tmsg = '<=== total time spent $tmsg'
}
return b.tdiff_in_ms(tmsg, b.bench_start_time, b.bench_end_time)
}
pub fn (b mut Benchmark) total_duration() i64 {
return (b.bench_end_time - b.bench_start_time)
}
////////////////////////////////////////////////////////////////////
fn (b mut Benchmark) tdiff_in_ms(s string, sticks i64, eticks i64) string {
@@ -89,4 +112,3 @@ fn (b mut Benchmark) tdiff_in_ms(s string, sticks i64, eticks i64) string {
fn now() i64 {
return time.ticks()
}