Skip to content

Commit da228e9

Browse files
committed
tools: implement a -repeats/-R N option to v repeat, to eliminate another need for platform dependent scripting
1 parent 8f95709 commit da228e9

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

cmd/tools/vrepeat.v

+21-7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ mut:
5050
struct Context {
5151
mut:
5252
run_count int
53+
repeats_count int
54+
current_run int
5355
series int
5456
warmup int
5557
show_help bool
@@ -309,7 +311,7 @@ fn (mut context Context) show_diff_summary() {
309311
gcmd := c(tgreen, context.results[0].cmd)
310312
context.show_summary_title('${context.results[0].atiming}, ${context.series} series, ${context.run_count} runs for ${gcmd:-57s}')
311313
} else {
312-
context.show_summary_title('Summary after ${context.series} series x ${context.run_count} runs (%s are relative to first command, or `base`).')
314+
context.show_summary_title('Summary after ${context.series} series x ${context.run_count} runs (%s are relative to first command, or `base`)')
313315
for i, r in context.results {
314316
first_marker = ' '
315317
cpercent := (r.atiming.average / base) * 100 - 100
@@ -360,6 +362,9 @@ fn (mut context Context) show_summary_title(line string) {
360362
if context.nmaxs > 0 {
361363
msg << 'discard maxs: ${context.nmaxs:2}'
362364
}
365+
if context.current_run > 0 {
366+
msg << 'repeat: ${context.current_run:2}'
367+
}
363368
println(msg.join(', '))
364369
}
365370

@@ -373,6 +378,7 @@ fn (mut context Context) parse_options() ! {
373378
fp.limit_free_args_to_at_least(1)!
374379
context.show_help = fp.bool('help', `h`, false, 'Show this help screen.')
375380
context.run_count = fp.int('runs', `r`, 10, 'Run count. Default: 10')
381+
context.repeats_count = fp.int('repeats', `R`, 1, 'Repeats count (it repeats everything, including reporting). Default: 1')
376382
context.warmup = fp.int('warmup', `w`, 2, 'Warmup run count. These are done *at the start* of each series, and the timings are ignored. Default: 2')
377383
context.series = fp.int('series', `s`, 1, 'Series count. `-s 2 -r 4 a b` => aaaabbbbaaaabbbb, while `-s 3 -r 2 a b` => aabbaabbaabb. Default: 1')
378384
context.ignore_failed = fp.bool('ignore', `e`, false, 'Ignore failed commands (returning a non 0 exit code).')
@@ -400,10 +406,7 @@ fn (mut context Context) parse_options() ! {
400406
exit(1)
401407
}
402408
context.commands = context.expand_all_commands(commands)
403-
context.results = []CmdResult{len: context.commands.len, cap: 20, init: CmdResult{
404-
outputs: []string{cap: 500}
405-
timings: []i64{cap: 500}
406-
}}
409+
context.reset_results()
407410
if context.use_newline {
408411
context.cline = '\n'
409412
context.cgoback = '\n'
@@ -413,12 +416,23 @@ fn (mut context Context) parse_options() ! {
413416
}
414417
}
415418

419+
fn (mut context Context) reset_results() {
420+
context.results = []CmdResult{len: context.commands.len, cap: 20, init: CmdResult{
421+
outputs: []string{cap: 500}
422+
timings: []i64{cap: 500}
423+
}}
424+
}
425+
416426
fn main() {
417427
// Make sure that we can measure various V executables
418428
// without influencing them, by presetting VEXE
419429
os.setenv('VEXE', '', true)
420430
mut context := Context{}
421431
context.parse_options()!
422-
context.run()
423-
context.show_diff_summary()
432+
for i := 1; i <= context.repeats_count; i++ {
433+
context.current_run = i
434+
context.reset_results()
435+
context.run()
436+
context.show_diff_summary()
437+
}
424438
}

0 commit comments

Comments
 (0)