Last active
July 7, 2022 18:57
-
-
Save camdencheek/dde9eb8c73f8ce3d882361e12edd8d3c to your computer and use it in GitHub Desktop.
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
// Start workers. They read from files and write to matches. | |
for i := 0; i < numWorkers; i++ { | |
rg := rg.Copy() | |
g.Go(func() error { | |
for ctx.Err() == nil { | |
// grab a file to work on | |
filesmu.Lock() | |
if len(files) == 0 { | |
filesmu.Unlock() | |
return nil | |
} | |
batchSize := 10 | |
if len(files) > batchSize { | |
batchSize = len(files) | |
} | |
batch := files[:batchSize] | |
files = files[batchSize:] | |
filesmu.Unlock() | |
for _, f := range batch { | |
// decide whether to process, record that decision | |
if !rg.matchPath.MatchPath(f.Name) { | |
filesSkipped.Inc() | |
continue | |
} | |
filesSearched.Inc() | |
// process | |
fm, err := rg.FindZip(zf, &f, sender.Remaining()) | |
if err != nil { | |
return err | |
} | |
match := len(fm.ChunkMatches) > 0 | |
if !match && patternMatchesPaths { | |
// Try matching against the file path. | |
match = rg.matchString(f.Name) | |
if match { | |
fm.Path = f.Name | |
} | |
} | |
if match == !isPatternNegated { | |
sender.Send(fm) | |
} | |
} | |
} | |
return nil | |
}) | |
} | |
name \ time/op /tmp/single.txt /tmp/batch1.txt /tmp/batch5.txt /tmp/batch10.txt | |
SearchRegex_large_fixed-10 6.28ms ± 1% 33.77ms ± 0% 34.20ms ± 0% 34.28ms ± 0% | |
SearchRegex_large_fixed_casesensitive-10 3.96ms ± 1% 18.22ms ± 0% 18.25ms ± 0% 18.46ms ± 0% | |
SearchRegex_large_re_dotstar-10 224ms ± 0% 1441ms ± 1% 1444ms ± 1% 1446ms ± 1% | |
SearchRegex_large_re_common-10 6.04ms ± 0% 28.56ms ± 0% 28.70ms ± 0% 28.73ms ± 0% | |
SearchRegex_large_re_anchor-10 64.4ms ± 1% 475.8ms ± 0% 476.4ms ± 0% 477.0ms ± 0% | |
SearchRegex_large_path/path_only-10 301µs ± 1% 301µs ± 0% 301µs ± 1% 302µs ± 0% | |
SearchRegex_large_path/content_only-10 6.91ms ± 2% 24.90ms ± 0% 25.01ms ± 0% 24.97ms ± 0% | |
SearchRegex_large_path/both_path_and_content-10 7.01ms ± 2% 25.39ms ± 0% 25.44ms ± 1% 25.35ms ± 0% | |
SearchRegex_small_fixed-10 133µs ± 0% 304µs ± 0% 305µs ± 0% 306µs ± 0% | |
SearchRegex_small_fixed_casesensitive-10 87.0µs ± 0% 206.5µs ± 1% 206.9µs ± 1% 207.2µs ± 0% | |
SearchRegex_small_re_dotstar-10 2.25ms ± 1% 7.76ms ± 0% 7.78ms ± 1% 7.77ms ± 0% | |
SearchRegex_small_re_common-10 91.9µs ± 6% 191.4µs ± 1% 192.2µs ± 2% 191.2µs ± 0% | |
SearchRegex_small_re_anchor-10 770µs ± 1% 3414µs ± 0% 3421µs ± 0% 3417µs ± 0% | |
name \ alloc/op /tmp/single.txt /tmp/batch1.txt /tmp/batch5.txt /tmp/batch10.txt | |
SearchRegex_large_fixed-10 15.8MB ± 0% 2.1MB ± 0% 2.1MB ± 0% 2.1MB ± 0% | |
SearchRegex_large_fixed_casesensitive-10 167kB ± 1% 165kB ± 0% 165kB ± 0% 166kB ± 0% | |
SearchRegex_large_re_dotstar-10 685MB ± 0% 669MB ± 0% 669MB ± 0% 669MB ± 0% | |
SearchRegex_large_re_common-10 7.74MB ± 0% 7.67MB ± 0% 7.68MB ± 0% 7.67MB ± 0% | |
SearchRegex_large_re_anchor-10 5.00MB ± 0% 5.00MB ± 0% 4.99MB ± 0% 5.00MB ± 0% | |
SearchRegex_large_path/path_only-10 1.03kB ± 1% 1.03kB ± 0% 1.03kB ± 1% 1.03kB ± 0% | |
SearchRegex_large_path/content_only-10 218kB ± 0% 217kB ± 0% 218kB ± 1% 218kB ± 1% | |
SearchRegex_large_path/both_path_and_content-10 219kB ± 1% 217kB ± 0% 216kB ± 0% 216kB ± 0% | |
SearchRegex_small_fixed-10 365kB ± 0% 64kB ± 0% 64kB ± 0% 64kB ± 0% | |
SearchRegex_small_fixed_casesensitive-10 6.46kB ± 0% 6.44kB ± 0% 6.44kB ± 0% 6.44kB ± 0% | |
SearchRegex_small_re_dotstar-10 4.52MB ± 0% 4.07MB ± 0% 4.07MB ± 0% 4.07MB ± 0% | |
SearchRegex_small_re_common-10 44.7kB ± 0% 44.4kB ± 0% 44.4kB ± 0% 44.4kB ± 0% | |
SearchRegex_small_re_anchor-10 19.9kB ± 1% 19.9kB ± 1% 20.0kB ± 1% 19.9kB ± 1% | |
name \ allocs/op /tmp/single.txt /tmp/batch1.txt /tmp/batch5.txt /tmp/batch10.txt | |
SearchRegex_large_fixed-10 6.64k ± 0% 6.59k ± 0% 6.59k ± 0% 6.59k ± 0% | |
SearchRegex_large_fixed_casesensitive-10 6.59k ± 0% 6.59k ± 0% 6.59k ± 0% 6.59k ± 0% | |
SearchRegex_large_re_dotstar-10 6.13M ± 0% 6.13M ± 0% 6.13M ± 0% 6.13M ± 0% | |
SearchRegex_large_re_common-10 74.8k ± 0% 74.8k ± 0% 74.8k ± 0% 74.8k ± 0% | |
SearchRegex_large_re_anchor-10 54.5k ± 0% 54.5k ± 0% 54.5k ± 0% 54.5k ± 0% | |
SearchRegex_large_path/path_only-10 20.0 ± 0% 20.0 ± 0% 20.0 ± 0% 20.0 ± 0% | |
SearchRegex_large_path/content_only-10 7.03k ± 0% 7.03k ± 0% 7.03k ± 0% 7.03k ± 0% | |
SearchRegex_large_path/both_path_and_content-10 7.03k ± 0% 7.03k ± 0% 7.03k ± 0% 7.03k ± 0% | |
SearchRegex_small_fixed-10 154 ± 0% 147 ± 0% 147 ± 0% 147 ± 0% | |
SearchRegex_small_fixed_casesensitive-10 146 ± 0% 146 ± 0% 146 ± 0% 146 ± 0% | |
SearchRegex_small_re_dotstar-10 40.5k ± 0% 40.5k ± 0% 40.5k ± 0% 40.5k ± 0% | |
SearchRegex_small_re_common-10 537 ± 0% 537 ± 0% 537 ± 0% 537 ± 0% | |
SearchRegex_small_re_anchor-10 296 ± 0% 296 ± 0% 296 ± 0% 296 ± 0% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment