6.47s Benchmark_100MB_Concurrent
2) via func:4.99s Benchmark_100MB_Concurrent
go func(start, end, i int, quit chan string) {BytesContainsCh1(b.Bytes(), start, end, find, ch)}(start, end, i, quit)
The way I'm using is "b" is a large buffer - hundreds of MB.I want to stop processing after the string is found using "quit".for i := 0; i < cores; i++ {go func(start, end, i int, quit chan string) {ch <- bytes.Contains(b.Bytes()[start:end], find)select {case <-quit:quit <- "bye"return}}(start, end, i, quit)
"bytes.Contains" is not interruptible - yes. I can improve the performance of the concurrent implementation
by stopping processing in other goroutines if the string is found in one of it,
by using the original source code in my program to make it interruptible.
I'm analyzing 100MB string.
Utilizing 8 cores is giving 2 times faster solution with concurrent version.
Each coroutine is working on 12.5MB. The worst case scenario is when the string error is at the end of the input.
If one goroutine finds it I can stop the other 7 form working. This will be good if the searched string is in the middle.
------------------------------------------------
Machine Mac-mini M1 16 MB:
------------------------------------------------
7.47s BigGrepBytes
3.81s BigGrepBytes1_Concurrent
------------------------------------------------
I'll post more + benchmark in another thread with a better focus on concurrent.