I'm implementing the following algorithm - sending result from 
bytes.Contains -
true or false to 1) channel directly and 2) via func.
I'm expecting 1)to be faster but actually 2) is faster:

4.99s vs 6.47s 

1) via channel:

for i := 0; i < cores; i++ {
  start := i * chunksize
  end := min(start+chunksize+overlap, filelen)
  go func(start, end, i int, quit chan string) {
      ch <- bytes.Contains(b.Bytes()[start:end], find)
   }(start, end, i, quit)

6.47s   Benchmark_100MB_Concurrent
2) via func:

for i := 0; i < cores; i++ {
  start := i * chunksize
  end := min(start+chunksize+overlap, filelen)
  go func(start, end, i int, quit chan string) {
      BytesContainsCh1(b.Bytes(), start, end, find, ch)
   }(start, end, i, quit)

func BytesContainsCh1(b []byte, start int, end int, find []byte, ch chan 
bool) { // <1>
   ch <- bytes.Contains(b[start:end], find)
}

4.99s Benchmark_100MB_Concurrent

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/fd2848df-1d06-4535-b91b-250832651f55n%40googlegroups.com.

Reply via email to