mirror of
https://github.com/junegunn/fzf.git
synced 2026-03-02 05:17:07 +08:00
Enhance --bench output with formatted times, match count, and selectivity
This commit is contained in:
15
src/core.go
15
src/core.go
@@ -278,15 +278,18 @@ func Run(opts *Options) (int, error) {
|
|||||||
|
|
||||||
if opts.Bench > 0 {
|
if opts.Bench > 0 {
|
||||||
// Benchmark mode: repeat scan for the given duration
|
// Benchmark mode: repeat scan for the given duration
|
||||||
|
totalItems := CountItems(snapshot)
|
||||||
|
var matchCount int
|
||||||
var times []time.Duration
|
var times []time.Duration
|
||||||
deadline := time.Now().Add(opts.Bench)
|
deadline := time.Now().Add(opts.Bench)
|
||||||
for time.Now().Before(deadline) {
|
for time.Now().Before(deadline) {
|
||||||
cache.Clear()
|
cache.Clear()
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
matcher.scan(MatchRequest{
|
result := matcher.scan(MatchRequest{
|
||||||
chunks: snapshot,
|
chunks: snapshot,
|
||||||
pattern: pattern})
|
pattern: pattern})
|
||||||
times = append(times, time.Since(start))
|
times = append(times, time.Since(start))
|
||||||
|
matchCount = result.merger.Length()
|
||||||
}
|
}
|
||||||
// Print stats
|
// Print stats
|
||||||
var total time.Duration
|
var total time.Duration
|
||||||
@@ -301,8 +304,14 @@ func Run(opts *Options) (int, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
avg := total / time.Duration(len(times))
|
avg := total / time.Duration(len(times))
|
||||||
fmt.Printf(" %d iterations avg: %v min: %v max: %v total: %v\n",
|
selectivity := float64(matchCount) / float64(totalItems) * 100
|
||||||
len(times), avg, minD, maxD, total)
|
fmt.Printf(" %d iterations avg: %.2fms min: %.2fms max: %.2fms total: %.2fs items: %d matches: %d (%.2f%%)\n",
|
||||||
|
len(times),
|
||||||
|
float64(avg.Microseconds())/1000,
|
||||||
|
float64(minD.Microseconds())/1000,
|
||||||
|
float64(maxD.Microseconds())/1000,
|
||||||
|
total.Seconds(),
|
||||||
|
totalItems, matchCount, selectivity)
|
||||||
return ExitOk, nil
|
return ExitOk, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user