mirror of
https://github.com/walles/moar.git
synced 2024-08-16 15:30:34 +03:00
Compare commits
3 Commits
f434895eef
...
eae1915b5e
Author | SHA1 | Date | |
---|---|---|---|
|
eae1915b5e | ||
|
11095496b2 | ||
|
d1fac66a23 |
25
m/search.go
25
m/search.go
@ -3,6 +3,7 @@ package m
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
@ -22,7 +23,7 @@ func (p *Pager) scrollToSearchHits() {
|
||||
}
|
||||
|
||||
firstHitPosition := p.findFirstHit(*lineNumber, nil, false)
|
||||
if firstHitPosition == nil {
|
||||
if firstHitPosition == nil && (*lineNumber != linenumbers.LineNumber{}) {
|
||||
// Try again from the top
|
||||
firstHitPosition = p.findFirstHit(linenumbers.LineNumber{}, lineNumber, false)
|
||||
}
|
||||
@ -75,7 +76,27 @@ func (p *Pager) findFirstHit(startPosition linenumbers.LineNumber, beforePositio
|
||||
}
|
||||
chunkSize := linesCount / chunkCount
|
||||
|
||||
log.Debugf("Searching %d lines across %d cores with %d lines per core", linesCount, chunkCount, chunkSize)
|
||||
log.Debugf("Searching %d lines across %d cores with %d lines per core...", linesCount, chunkCount, chunkSize)
|
||||
t0 := time.Now()
|
||||
defer func() {
|
||||
linesPerSecond := float64(linesCount) / time.Since(t0).Seconds()
|
||||
linesPerSecondS := fmt.Sprintf("%.0f", linesPerSecond)
|
||||
if linesPerSecond > 7_000_000.0 {
|
||||
linesPerSecondS = fmt.Sprintf("%.0fM", linesPerSecond/1000_000.0)
|
||||
} else if linesPerSecond > 7_000.0 {
|
||||
linesPerSecondS = fmt.Sprintf("%.0fk", linesPerSecond/1000.0)
|
||||
}
|
||||
|
||||
if linesCount > 0 {
|
||||
log.Debugf("Searched %d lines in %s at %slines/s or %s/line",
|
||||
linesCount,
|
||||
time.Since(t0),
|
||||
linesPerSecondS,
|
||||
time.Since(t0)/time.Duration(linesCount))
|
||||
} else {
|
||||
log.Debugf("Searched %d lines in %s at %slines/s", linesCount, time.Since(t0), linesPerSecondS)
|
||||
}
|
||||
}()
|
||||
|
||||
// Each parallel search will start at one of these positions
|
||||
searchStarts := make([]linenumbers.LineNumber, chunkCount)
|
||||
|
Loading…
Reference in New Issue
Block a user