-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save 5% of process line time by skipping creating a string slice and … (
#13) * Save 5% of process line time by skipping creating a string slice and giving direct access to the indexed results * Add overall extractor benchmarking * Fix out of bounds bug
- Loading branch information
Showing
6 changed files
with
86 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package extractor | ||
|
||
type SliceSpaceExpressionContext struct { | ||
linePtr string | ||
indices []int | ||
} | ||
|
||
func (s *SliceSpaceExpressionContext) GetMatch(idx int) string { | ||
sliceIndex := idx * 2 | ||
if sliceIndex < 0 || sliceIndex+1 >= len(s.indices) { | ||
return "" | ||
} | ||
start := s.indices[sliceIndex] | ||
end := s.indices[sliceIndex+1] | ||
if start < 0 || end < 0 { | ||
return "" | ||
} | ||
return s.linePtr[start:end] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package benchmark_test | ||
|
||
import ( | ||
"rare/pkg/extractor" | ||
"testing" | ||
) | ||
|
||
func batchInputGenerator(batches int, batchSize int) <-chan []extractor.BString { | ||
c := make(chan []extractor.BString, 128) | ||
go func() { | ||
for i := 0; i < batches; i++ { | ||
batch := make([]extractor.BString, batchSize) | ||
for j := 0; j < batchSize; j++ { | ||
batch[j] = extractor.BString("abcdefg 123") | ||
} | ||
c <- batch | ||
} | ||
close(c) | ||
}() | ||
return c | ||
} | ||
|
||
func BenchmarkExtractor(b *testing.B) { | ||
total := 0 | ||
for n := 0; n < b.N; n++ { | ||
gen := batchInputGenerator(10000, 100) | ||
extractor, _ := extractor.New(gen, &extractor.Config{ | ||
Regex: `(\d{3})`, | ||
Extract: "{bucket {1} 10}", | ||
Workers: 2, | ||
}) | ||
reader := extractor.ReadChan() | ||
for val := range reader { | ||
total++ | ||
if val[0].Extracted != "120" { | ||
panic("NO MATCH") | ||
} | ||
} // Drain reader | ||
} | ||
} |