Skip to content

Commit 4c5c620

Browse files
Speed up containsTimestamp
Iterate over string bytes instead of runes to avoid unnecessary utf-8 decoding overhead: ``` goos: linux goarch: amd64 pkg: github.com/coroot/logparser │ main │ HEAD │ │ sec/op │ sec/op vs base │ ContainsTimestamp-8 56.71n ± 2% 42.36n ± 1% -25.32% (p=0.000 n=10) ``` Signed-off-by: Alexander Yastrebov <yastrebov.alex@gmail.com>
1 parent 49b0847 commit 4c5c620

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

timestamp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ func containsTimestamp(line string) bool {
99
line = line[:lookForTimestampLimit]
1010
}
1111
var digits, colons int
12-
for _, r := range line {
12+
for i := 0; i < len(line); i++ {
13+
r := line[i]
1314
switch {
1415
case r >= '0' && r <= '9':
1516
digits++

0 commit comments

Comments
 (0)