Skip to content
Myr

Add --bench flag for repeatable filter-mode timing

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

fzf --filter PATTERN --bench 3s < input Repeats matcher.scan() for the given duration, clears cache between iterations, and prints stats (iterations, avg, min, max) to stderr.

authored by Junegunn Choi · committed by Junegunn Choi · parent 55193ee · Browse files · 2 files+45 added−1 removed
This commit

State

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

Diff stats

2 files+45 added−1 removed

  • other:+45 added−1 removed

2 files+45 added−1 removed

modified:src/core.go+33 added-1 removed
1// Package fzf implements fzf, a command-line fuzzy finder.2package fzf34import (5 "fmt"6 "maps"7 "os"8 "sync"9 "time"
171 unmodified lines
181 }182 }183184 // Reader184 streamingFilter := opts.Filter != nil && !sort && !opts.Tac && !opts.Sync185 streamingFilter := opts.Filter != nil && !sort && !opts.Tac && !opts.Sync && opts.Bench == 0186 var reader *Reader187 if !streamingFilter {188 reader = NewReader(func(data []byte) bool {189 return chunkList.Push(data)
84 unmodified lines
274 eventBox.WaitFor(EvtReadFin)275276 // NOTE: Streaming filter is inherently not compatible with --tail277 snapshot, _, _ := chunkList.Snapshot(opts.Tail)278279 if opts.Bench > 0 {280 // Benchmark mode: repeat scan for the given duration281 var times []time.Duration282 deadline := time.Now().Add(opts.Bench)283 for time.Now().Before(deadline) {284 cache.Clear()285 start := time.Now()286 matcher.scan(MatchRequest{287 chunks: snapshot,288 pattern: pattern})289 times = append(times, time.Since(start))290 }291 // Print stats292 var total time.Duration293 minD, maxD := times[0], times[0]294 for _, d := range times {295 total += d296 if d < minD {297 minD = d298 }299 if d > maxD {300 maxD = d301 }302 }303 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)306 return ExitOk, nil307 }308309 result := matcher.scan(MatchRequest{310 chunks: snapshot,311 pattern: pattern})312 for i := 0; i < result.merger.Length(); i++ {
268 unmodified lines
modified:src/options.go+12 added
6 unmodified lines
7 "os"8 "regexp"9 "strconv"10 "strings"11 "time"12 "unicode"1314 "github.com/junegunn/fzf/src/algo"15 "github.com/junegunn/fzf/src/tui"
661 unmodified lines
677 WalkerRoot []string678 WalkerSkip []string679 Version bool680 Help bool681 Bench time.Duration682 CPUProfile string683 MEMProfile string684 BlockProfile string685 MutexProfile string
2688 unmodified lines
3374 if err != nil {3375 return err3376 }3377 opts.WalkerSkip = filterNonEmpty(strings.Split(str, ","))3378 case "--bench":3379 str, err := nextString("duration required (e.g. 3s, 500ms)")3380 if err != nil {3381 return err3382 }3383 dur, err := time.ParseDuration(str)3384 if err != nil {3385 return errors.New("invalid duration for --bench: " + str)3386 }3387 opts.Bench = dur3388 case "--profile-cpu":3389 if opts.CPUProfile, err = nextString("file path required: cpu"); err != nil {3390 return err3391 }
510 unmodified lines