Golang Chan send receive test data

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Test code:

Package Main

Import (
"FMT"
"Time"
)

Const (
num = 10000000//test 10 million times send and receive
)

Func Main () {
TestChan2 ()
}

Func TestChan2 () {
ST: = time. Now (). Unixnano ()

c: = make (chan int)

Go func () {
var n int
For n = range C {
}
Fmt. Printf ("task TestChan2 cost%d \ r \ n" (time. Now (). Unixnano ()-st)/int64 (Time.millisecond))
Fmt. Printf ("%d", N)

}()

For I: = 0; i < num; i++ {
C <-I
}
Close (c)//closes the channel after sending, and exits the for Range loop in the process

Sleep for a while and make sure to receive Chan complete
Time. Sleep (3 * time. Second)

}

Execution Result:

Test the data on a Win7 notebook as follows:

2.7 to 2.9 seconds to finish sending and receiving.

The data tested on a Docker virtual machine is as follows:

4.9 seconds to 5.2 seconds to complete

Perform results on a single Linux physical machine

Completed in 3.5-4.1 seconds

Some of Chan's tips are:

http://my.oschina.net/goskyblue/blog/191149

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.