On May 8, 2022, at 3:28 PM, Const V <ths...@gmail.com> wrote:
pre-allocating a buffer is not an option, it should be dynamic
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/23d14932-17a3-4c68-a72d-f3e0b97dcb55n%40googlegroups.com.
write to stdout is not working for MB long strings
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/IUMIxWx9aLk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b1259910-58ca-4a57-bb05-1dde2fc73443n%40googlegroups.com.
BigGrepStrFnd - Boyer-Moore (grep)
BigGrepBytes - Rabin-Karp
BigGrepStr - Rabin-Karp
BigGrepScan - search with sliding window
Additionally implemented them using concurrency.
Tested on 100 files containing one 100MB line. Searching for 20 character string at the end of the line as worst case scenario.
The program is reading each file and loading the 100MB line in the memory for analysis. With 100 files I'm getting consistent results.
Here are the results. I needed to know also the memory requirements.
Created two profiles:
go test -run=NONE -bench=cpuprofile
go test -run=NONE -bench=memprofile
Then analyzed with go tool pprof
Computer Mac-mini M1 8 cores, 16 GB
Concurrent versions are performing the search in parallel on 8 slices of the 100MB line.
Fastest
3.04s -60.47GB - BigGrepBytes_Concurrent ~2.85 times faster than non concurrent.
8.55s - 60.48GB BigGrepBytes
From non concurrent versions the fastest is BigGrepStrFnd. Note it has bigger memory requirements.
5.44s - 72.96GB BigGrepStrFnd - Boyer-Moore (grep) ~1.63 times faster than BigGrepBytes
3.82s - 72.93GB BigGrepStrFndConcurrent
----
go test -run=NONE -bench=cpuprofile
goos: darwin
goarch: arm64
pkg: mobiledatabooks.com/biggrep
Benchmark_100MB_End__20charsBigGrepBytes_Concurrent-8 1 7653778209 ns/op
Benchmark_100MB_End__20charsBigGrepBytes_-8 1 12326358083 ns/op
Benchmark_100MB_End__20charsBigGrepScan__-8 1 14934611708 ns/op
Benchmark_100MB_End__20charsBigGrepStr___-8 1 13178685417 ns/op
Benchmark_100MB_End__20charsBigGrepStr___Concurrent-8 1 8302944958 ns/op
Benchmark_100MB_End__20charsBigGrepStrFnd-8 1 8765527416 ns/op
Benchmark_100MB_End__20charsBigGrepStrFndConcurrent-8 1 7361004166 ns/op
Benchmark_100MB_End__20charsBigGrepScan__Concurrent-8 1 8413663834 ns/op
PASS
ok mobiledatabooks.com/biggrep 81.204s
----
----
Type: cpu
Time: Jun 8, 2022 at 10:15pm (PDT)
Duration: 81.11s, Total samples = 89.36s (110.17%)
Active filters:
focus=Benchmark
hide=benchm
show=Benchmark
Showing nodes accounting for 47.88s, 53.58% of 89.36s total
flat flat% sum% cum cum%
10.37s 11.60% 11.60% 10.37s 11.60% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepScan__
8.99s 10.06% 21.67% 8.99s 10.06% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepStr___
8.55s 9.57% 31.23% 8.55s 9.57% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepBytes_
5.44s 6.09% 37.32% 5.44s 6.09% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepStrFnd
4.02s 4.50% 41.82% 4.02s 4.50% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepStr___Concurrent
3.82s 4.27% 46.09% 3.82s 4.27% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepStrFndConcurrent
3.65s 4.08% 50.18% 3.65s 4.08% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepScan__Concurrent
3.04s 3.40% 53.58% 3.04s 3.40% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepBytes_Concurrent
----
----
Type: alloc_space
Time: Jun 8, 2022 at 10:17pm (PDT)
Active filters:
focus=Benchmark
hide=benchm
show=Benchmark
Showing nodes accounting for 533.60GB, 100% of 533.61GB total
flat flat% sum% cum cum%
72.96GB 13.67% 13.67% 72.96GB 13.67% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepStrFnd
72.95GB 13.67% 27.34% 72.95GB 13.67% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepStr___Concurrent
72.94GB 13.67% 41.01% 72.94GB 13.67% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepStr___
72.93GB 13.67% 54.68% 72.93GB 13.67% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepStrFndConcurrent
60.48GB 11.33% 66.01% 60.48GB 11.33% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepBytes_
60.47GB 11.33% 77.35% 60.47GB 11.33% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepBytes_Concurrent
60.45GB 11.33% 88.67% 60.45GB 11.33% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepScan__Concurrent
60.43GB 11.33% 100% 60.43GB 11.33% mobiledatabooks.com/biggrep.Benchmark_100MB_End__20charsBigGrepScan__
----3.82s