Skip to content
Myr

Enhance --bench output with formatted times, match count, and selectivity

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 90c4269 · Browse files · 1 file+12 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+12 added−3 removed

  • other:+12 added−3 removed

1 file+12 added−3 removed

modified:src/core.go+12 added-3 removed
276 unmodified lines
277 snapshot, _, _ := chunkList.Snapshot(opts.Tail)278279 if opts.Bench > 0 {280 // Benchmark mode: repeat scan for the given duration281 totalItems := CountItems(snapshot)282 var matchCount int283 var times []time.Duration284 deadline := time.Now().Add(opts.Bench)285 for time.Now().Before(deadline) {286 cache.Clear()287 start := time.Now()286 matcher.scan(MatchRequest{288 result := matcher.scan(MatchRequest{289 chunks: snapshot,290 pattern: pattern})291 times = append(times, time.Since(start))292 matchCount = result.merger.Length()293 }294 // Print stats295 var total time.Duration296 minD, maxD := times[0], times[0]
6 unmodified lines
303 maxD = d304 }305 }306 avg := total / time.Duration(len(times))304 fmt.Printf(" %d iterations avg: %v min: %v max: %v total: %v\n",305 len(times), avg, minD, maxD, total)307 selectivity := float64(matchCount) / float64(totalItems) * 100308 fmt.Printf(" %d iterations avg: %.2fms min: %.2fms max: %.2fms total: %.2fs items: %d matches: %d (%.2f%%)\n",309 len(times),310 float64(avg.Microseconds())/1000,311 float64(minD.Microseconds())/1000,312 float64(maxD.Microseconds())/1000,313 total.Seconds(),314 totalItems, matchCount, selectivity)315 return ExitOk, nil316 }317318 result := matcher.scan(MatchRequest{
271 unmodified lines