{"id":195574,"date":"2013-09-27T23:09:03","date_gmt":"2013-09-27T19:09:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=195574"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=195574","title":{"rendered":"<span class=\"post_title\">Go: \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041b\u044e\u0431\u043b\u044e Go, \u043b\u044e\u0431\u043b\u044e \u0435\u0433\u043e \u0445\u0432\u0430\u043b\u0438\u0442\u044c (\u0431\u044b\u0432\u0430\u0435\u0442 \u0434\u0430\u0436\u0435, \u043f\u0440\u0438\u0432\u0438\u0440\u0430\u044e \u0441\u043b\u0435\u0433\u0430), \u043b\u044e\u0431\u043b\u044e \u043e \u043d\u0435\u043c \u0441\u0442\u0430\u0442\u044c\u0438. \u041f\u0440\u043e\u0447\u0438\u0442\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u044e \u201c<a href=\"http:\/\/habrahabr.ru\/post\/195464\/\">Go: \u0414\u0432\u0430 \u0433\u043e\u0434\u0430 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u043d\u0435<\/a> \u201d, \u043f\u043e\u0442\u043e\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u044b. \u0421\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u2014 \u043e\u043f\u0442\u0438\u043c\u0438\u0441\u0442\u044b! \u0425\u043e\u0442\u044f\u0442 \u0432\u0435\u0440\u0438\u0442\u044c \u0432 \u043b\u0443\u0447\u0448\u0435\u0435. <br \/>  <a name=\"habracut\"><\/a><br \/>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Go \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0432\u043e\u0439 \u0448\u0435\u0434\u0443\u043b\u0435\u0440 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b. (\u0423 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.) \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u0430\u043d\u0430\u043b\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u043e\u0447\u0435\u043d\u044c \u0431\u044b\u0441\u0442\u0440\u043e. \u041d\u043e \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c Go \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c 2 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0442\u043e\u043a\u0430, \u0442\u043e Go \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u043d\u0430\u043b\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u0430\u0434\u0430\u0442\u044c. \u041d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u0435\u0431\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u0430\u043d\u0430\u043b\u043e\u0432. \u0422\u0435\u043c \u0431\u043e\u043b\u0435\u0435, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u0430\u043d\u0430\u043b\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0447\u0430\u0441\u0442\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c Go \u0441 \u043e\u0434\u043d\u0438\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/p>\n<p>  channel01.go  <\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot; import &quot;time&quot; import &quot;runtime&quot;  type Mes struct{ \ti int }   func main() {          numcpu := runtime.NumCPU()     fmt.Println(&quot;NumCPU&quot;, numcpu)     \/\/runtime.GOMAXPROCS(numcpu)     runtime.GOMAXPROCS(1)      \tch1 := make(chan int) \tch2 := make(chan float64)  \tgo func() { \t\tfor i := 0; i &lt; 1000000; i++ { \t\t\tch1 &lt;- i \t\t} \t\tch1 &lt;- -1 \t\tch2 &lt;- 0.0 \t}() \tgo func() {           total := 0.0 \t\tfor { \t\t\tt1 := time.Now().UnixNano() \t\t\tfor i := 0; i &lt; 100000; i++ { \t\t\t\tm := &lt;-ch1 \t\t\t\tif m == -1 { \t\t\t\t\tch2 &lt;- total \t\t\t\t} \t\t\t} \t\t\tt2 := time.Now().UnixNano() \t\t\tdt := float64(t2 - t1) \/ 1000000.0 \t\t\ttotal += dt \t\t\tfmt.Println(dt) \t\t} \t}() \t \tfmt.Println(&quot;Total:&quot;, &lt;-ch2, &lt;-ch2) }  <\/code><\/pre>\n<pre><code class=\"bash\">users-iMac:channel user$ go run channel01.go  NumCPU 4 23.901 24.189 23.957 24.072 24.001 23.807 24.039 23.854 23.798 24.1 Total: 239.718 0 <\/code><\/pre>\n<p>  \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u044f\u0434\u0440\u0430, \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0432 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<pre><code class=\"go\">    runtime.GOMAXPROCS(numcpu)     \/\/runtime.GOMAXPROCS(1) <\/code><\/pre>\n<pre><code class=\"bash\">users-iMac:channel user$ go run channel01.go  NumCPU 4 543.092 534.985 535.799 533.039 538.806 533.315 536.501 533.261 537.73 532.585 Total: 5359.113 0 <\/code><\/pre>\n<p>  20 \u0440\u0430\u0437 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0439? \u0412 \u0447\u0435\u043c \u043f\u043e\u0434\u0432\u043e\u0445? \u0420\u0430\u0437\u043c\u0435\u0440 \u043a\u0430\u043d\u0430\u043b\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 1. <\/p>\n<pre><code class=\"go\">\tch1 := make(chan int) <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u0442\u0430\u0432\u0438\u043c 100. <\/p>\n<pre><code class=\"go\">\tch1 := make(chan int, 100) <\/code><\/pre>\n<p>  \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 1 \u043f\u043e\u0442\u043e\u043a  <\/p>\n<pre><code class=\"go\">users-iMac:channel user$ go run channel01.go  NumCPU 4 9.704 9.618 9.178 9.84 9.869 9.461 9.802 9.743 9.877 9.756 Total: 0 96.848 <\/code><\/pre>\n<p>  \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 4 \u043f\u043e\u0442\u043e\u043a\u0430  <\/p>\n<pre><code class=\"go\">users-iMac:channel user$ go run channel01.go  NumCPU 4 17.046 17.046 16.71 16.315 16.542 16.643 17.69 16.387 17.162 15.232 Total: 0 166.77300000000002 <\/code><\/pre>\n<p>  \u0412\u0441\u0435\u0433\u043e \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0439, \u043d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. <\/p>\n<h5>\u041f\u0440\u0438\u043c\u0435\u0440 \u201c\u043a\u0430\u043d\u0430\u043b \u043a\u0430\u043d\u0430\u043b\u043e\u0432\u201d<\/h5>\n<pre><code class=\"go\">package main  import &quot;fmt&quot; import &quot;time&quot; import &quot;runtime&quot;  type Mes struct{ \tch chan int }   func main() {          numcpu := runtime.NumCPU()     fmt.Println(&quot;NumCPU&quot;, numcpu)     \/\/runtime.GOMAXPROCS(numcpu)     runtime.GOMAXPROCS(1)      \tch1 := make(chan chan int, 100) \tch2 := make(chan float64, 1)  \tgo func() { \t\tt1 := time.Now().UnixNano() \t\tfor i := 0; i &lt; 1000000; i++ {       \t\tch := make(chan int, 100) \t\t\tch1 &lt;- ch \t\t\t&lt;- ch \t\t} \t\tt2 := time.Now().UnixNano() \t\tdt := float64(t2 - t1) \/ 1000000.0 \t\tfmt.Println(dt) \t\tch2 &lt;- 0.0 \t}() \tgo func() { \t\tfor i := 0; i &lt; 1000000; i++ { \t\t\tch := &lt;-ch1 \t\t\tch &lt;- i \t\t} \t\tch2 &lt;- 0.0 \t}()  \t&lt;-ch2 \t&lt;-ch2 } <\/code><\/pre>\n<p>  \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 1 \u043f\u043e\u0442\u043e\u043a  <\/p>\n<pre><code class=\"bash\">users-iMac:channel user$ go run channel03.go  NumCPU 4 1041.489 <\/code><\/pre>\n<p>  \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 4 \u043f\u043e\u0442\u043e\u043a\u0430  <\/p>\n<pre><code class=\"bash\">users-iMac:channel user$ go run channel03.go  NumCPU 4 11170.616 <\/code><\/pre>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 8 \u044f\u0434\u0435\u0440 \u0438 \u0432\u044b \u043f\u0438\u0448\u0438\u0442\u0435 \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 Go, \u0432\u0430\u043c \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 Go \u0432 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0430 \u043c\u043e\u0436\u0435\u0442, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c 8 \u043e\u0434\u043d\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u0430 \u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c\u0438 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 Go. \u0423 \u043d\u0430\u0441 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0438\u043d\u0435 \u0431\u044b\u043b \u0441\u0435\u0440\u0432\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u0441 \u043e\u0434\u043d\u043e-\u044f\u0434\u0435\u0440\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 4\u0445 \u0441\u0442\u0430\u043b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u0430 10% \u043c\u0435\u043d\u044c\u0448\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>  \u0427\u0442\u043e \u0437\u043d\u0430\u0447\u0430\u0442 \u044d\u0442\u0438 \u0446\u0438\u0444\u0440\u044b? \u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0441\u0442\u043e\u044f\u043b\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c 3000 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0432 \u043e\u0434\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0447\u0438\u0441\u043b\u0430: 1, 2, 3, 4, 5\u2026 \u043c\u043e\u0436\u0435\u0442, \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0439) \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c 3000 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043a\u0430\u043d\u0430\u043b\u0430\u043c\u0438. \u0421 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0438 \u044f\u0434\u0435\u0440 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0441\u0442\u0435\u0442 \u043d\u0435 \u0442\u0430\u043a \u0440\u044c\u044f\u043d\u043e, \u043a\u0430\u043a \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c. 3000 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0434\u043b\u044f Go \u2014 \u044d\u0442\u043e \u043d\u0435\u043a\u0438\u0439 \u043f\u0440\u0435\u0434\u0435\u043b \u043d\u0430 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u043e\u0431\u043e\u0440\u0443\u0434\u043e\u0432\u0430\u043d\u0438\u0438.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/195574\/\"> http:\/\/habrahabr.ru\/post\/195574\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041b\u044e\u0431\u043b\u044e Go, \u043b\u044e\u0431\u043b\u044e \u0435\u0433\u043e \u0445\u0432\u0430\u043b\u0438\u0442\u044c (\u0431\u044b\u0432\u0430\u0435\u0442 \u0434\u0430\u0436\u0435, \u043f\u0440\u0438\u0432\u0438\u0440\u0430\u044e \u0441\u043b\u0435\u0433\u0430), \u043b\u044e\u0431\u043b\u044e \u043e \u043d\u0435\u043c \u0441\u0442\u0430\u0442\u044c\u0438. \u041f\u0440\u043e\u0447\u0438\u0442\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u044e \u201c<a href=\"http:\/\/habrahabr.ru\/post\/195464\/\">Go: \u0414\u0432\u0430 \u0433\u043e\u0434\u0430 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u043d\u0435<\/a> \u201d, \u043f\u043e\u0442\u043e\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u044b. \u0421\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u2014 \u043e\u043f\u0442\u0438\u043c\u0438\u0441\u0442\u044b! \u0425\u043e\u0442\u044f\u0442 \u0432\u0435\u0440\u0438\u0442\u044c \u0432 \u043b\u0443\u0447\u0448\u0435\u0435.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-195574","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/195574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=195574"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/195574\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=195574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=195574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=195574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}