I've benchmarking this go tour example with buffered channel.http://tour.golang.org/#64
Doesn't it mean that buffered channel should perform faster than unbuffered
because there is no wait-time that is blocking?
What exactly are you trying to measure?
The difference between unbuffered and buffered channels is that with a
buffered channel, the sender does not block even if the receiver is
not ready to receive, unless the buffer is full.
In this example, each goroutine exits directly after sending. Moreover,
the receiver is always ready, because it does not expect the messages
in a specific order. Thus, changing from unbuffered to buffered channels
makes no difference for the performance of the example.
As the example splits up the sum calculation into two goroutines, setting
-cpu=2 (or higher) should be faster than 1, if you system has 2 or more
cpu cores. However, the most cpu time is spent in the creation of the
slice, which is non-parallelized.
It is hard to find a concrete example of benefit of using buffered channels.
Consider a program witch works on jobs in a pipeline. Each job has to run
through each step of the pipeline sequentially. The pipeline steps are
implemented as goroutines, and the jobs are submitted through channels.
Each step take the same time in average, but time varies from job to job.
With unbuffered channels, a pipeline step must wait for the next step
to become ready, and cannot work on the next job in the meantime. Buffered
channel allow to store intermediate results in the buffer, which leads
to a better utilization in summary.
for an example implementation with
3 pipeline steps, which take between 0 and 100 milliseconds for each step.
The program runs measurably faster when "make(chan int)" is replaced by e.g.
"make(chan int, 10)".
(You need to execute the program locally, because of the playgrounds
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 firstname.lastname@example.org.
For more options, visit https://groups.google.com/groups/opt_out.