tag:blogger.com,1999:blog-58964341030244735612024-03-12T22:28:46.422-07:00Go Programming and ConsultingThe main topic of this blog is the new Go programming language from Google Inc., how it develops and how it is situated in the software landscape.Ivohttp://www.blogger.com/profile/03262836162946789511noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-5896434103024473561.post-61328969704960391932012-06-01T02:34:00.001-07:002012-06-01T02:34:15.644-07:00The Zeus programming editor for Windows and Ubuntu (under wine).<span lang="">This fast and lean editor packed with features for programming in a whole bunch of languages now also has full support for working with Go. <br />
<br />
Particularly impressive is the code complete or intellisense feature built-in for Go, which is superior to all code completion features I have seen so far in other ide's (also on Linux), e.g. when opening the parameter list it shows the types of parameters to enter. <br />
<br />
Furthermore Zeus offers code folding, a very handy feature I also haven't yet seen in other editors, a Goto Definition feature (very nice for browsing the Go source), and a whole bunch of code snippets (templates). <br />
<br />
Zeus has the same capabilities and speed Visual Studio offers, but now Go developers have it for their favorite language! <br />
<br />
See it in action in: </span><a href="http://www.youtube.com/watch?v=CZ5Yl0KnbKs&feature=youtu.be"><u><span style="color: blue; font-size: small;"><span style="color: blue; font-size: small;"><span lang="">http://www.youtube.com/watch?v=CZ5Yl0KnbKs&feature=youtu.be</span></span></span></u><span style="color: blue; font-size: small;"><span style="color: blue; font-size: small;"></span></span></a><br />
<span style="font-size: small;"><span lang=""></span></span><br />
<span style="font-size: small;">Go check it out at: </span><h4>
<a href="http://www.zeusedit.com/"><span lang="">http://www.zeusedit.com/</span></a></h4>Ivohttp://www.blogger.com/profile/03262836162946789511noreply@blogger.com0tag:blogger.com,1999:blog-5896434103024473561.post-65469641844784653452012-03-17T03:55:00.001-07:002012-03-17T03:57:57.032-07:00Book: The Way to Go<div class="MsoNormal"><span lang="EN-US">My book on the Go language has been published:</span></div><div class="MsoNormal"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyCChCuems6VDc0ZvjvYTCZzN_TfpCqUIKEqE-xjPfbwpXOyen_2EtxoNyjpqYGtCGkUHiQhckr8UhVDTZDLOYqEXZCAWkxvkrhfiOuTEhbAIhBBx7GyttMv0Llo3wIwzpD8bHbsFjM5g/s1600/gobook.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyCChCuems6VDc0ZvjvYTCZzN_TfpCqUIKEqE-xjPfbwpXOyen_2EtxoNyjpqYGtCGkUHiQhckr8UhVDTZDLOYqEXZCAWkxvkrhfiOuTEhbAIhBBx7GyttMv0Llo3wIwzpD8bHbsFjM5g/s1600/gobook.jpg" /></a></div><span style="color: #666666; font-family: Arial, sans-serif;"><span style="font-size: 12px;"><br />
</span></span></div><div class="MsoNormal"><span lang="EN-US" style="color: #d14f5e; font-family: 'Trebuchet MS', sans-serif; font-size: 18pt;">The Way to Go<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-family: 'Trebuchet MS', sans-serif; font-size: 12pt;">A Thorough Introduction to the Go Programming Language<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: Arial, sans-serif; font-size: 9pt;"><a href="http://bookstore.iuniverse.com/Author/Default.aspx?BookworksSId=SKU-000541025"><span lang="EN-US" style="color: black; text-decoration: none;">By Dr. Ivo Balbaert</span></a></span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 9pt;"><o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 9pt;">Published: 3/9/2012 by IUniverse<o:p></o:p></span></div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 9pt;">Format:Perfect Bound Softcover(B/W)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 9pt;">Pages:628<o:p></o:p></span></div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 9pt;">Size:7.5x9.25<o:p></o:p></span></div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 9pt;">ISBN:978-1-46976-916-5<o:p></o:p></span></div><div class="MsoNormal" style="line-height: 13.5pt;"><br />
</div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 9pt;">Its main purpose is to clearly describe all the concepts of Go through many examples and exercises, and as such is suited for students, junior developers and developers new to the language alike. The code is Go1 ready. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 9pt;">It is a print-on-demand book, so trees are not unnecessarily killed for it.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: 13.5pt;"><br />
</div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 9pt;">It is available through Barnes and Noble:<o:p></o:p></span></div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US"><a href="http://www.barnesandnoble.com/w/the-way-to-go-ivo-balbaert/1109457121?ean=9781469769165&itm=1&usri=ivo+balbaert">http://www.barnesandnoble.com/w/the-way-to-go-ivo-balbaert/1109457121?ean=9781469769165&itm=1&usri=ivo+balbaert</a></span></div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US">and Amazon:</span></div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US"><a href="http://www.amazon.com/dp/1469769166/ref=rdr_ext_tmb">http://www.amazon.com/dp/1469769166/ref=rdr_ext_tmb</a></span></div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US">but also as an e-book:</span></div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US"><a href="http://www.diesel-ebooks.com/item/9781469769165/Balbaert-Ivo-The-Way-to-Go-A-Thorough-Introduction-to-the-Go-Programming-Language/1.html">http://www.diesel-ebooks.com/item/9781469769165/Balbaert-Ivo-The-Way-to-Go-A-Thorough-Introduction-to-the-Go-Programming-Language/1.html</a></span></div><div class="MsoNormal" style="line-height: 13.5pt;"><br />
</div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US">Publisher site: <a href="http://bookstore.iuniverse.com/Products/SKU-000541025/The-Way-to-Go.aspx">http://bookstore.iuniverse.com/Products/SKU-000541025/The-Way-to-Go.aspx</a></span></div><div class="MsoNormal" style="line-height: 13.5pt;"><br />
</div><div class="MsoNormal" style="line-height: 13.5pt;"><span lang="EN-US">I maintain a website about the book where the code can be downloaded, and updates, articles and errata will be added: <a href="https://sites.google.com/site/thewaytogo2012/">https://sites.google.com/site/thewaytogo2012/</a></span></div>Ivohttp://www.blogger.com/profile/03262836162946789511noreply@blogger.com5tag:blogger.com,1999:blog-5896434103024473561.post-66660212826939338362011-11-12T03:19:00.000-08:002011-11-12T03:19:32.719-08:00Go has turned 2 years!Indeed on Nov 10 2009 the Go-team at Google made their work public.<br />
Go has come a long way in these 2 years, thanks to the brilliant team and hundreds of contributors from all over the world. Early 2012 Go 1 will be launched as a hallmark to the world announcing that it is ready for mainstream adoption, being stable and supported for years to come. The past year has seen a great number of refinements and additions so that Go is now faster than ever, building upon a complete standard library and surrounded by hundreds of peripheral 3rd party projects<br />
(see <a href="http://godashboard.appspot.com/package">http://godashboard.appspot.com/package</a>).<br />
Go has also made its way in the cloud in Google App Engine, where it will soon be equal in possibilities to the Java and Python environments.<br />
Already now the list of business projects using Go is impressive:<br />
<a href="http://go-lang.cat-v.org/organizations-using-go">http://go-lang.cat-v.org/organizations-using-go</a><br />
In only 2 years it can present an equal or greater amount of references than Ruby:<br />
(<a href="http://www.ruby-lang.org/en/documentation/success-stories">http://www.ruby-lang.org/en/documentation/success-stories</a>/).<br />
Every day on github alone around 10 projects using Go are created or updated (<a href="https://github.com/languages/Go/created">https://github.com/languages/Go/created</a>)<br />
The release of Go1 will also see the publication of an ever growing number of published books on Go and its applications.<br />
See also the GopherTimes (<a href="http://www.gophertimes.com/">www.gophertimes.com</a>) for announcements of the steps and milestones in the evolution and adoption of Go.<br />
<div><br />
</div>Ivohttp://www.blogger.com/profile/03262836162946789511noreply@blogger.com0tag:blogger.com,1999:blog-5896434103024473561.post-22828189205217987482011-11-06T04:21:00.000-08:002011-11-06T04:21:00.919-08:00An error-handling scheme with closures<div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;">Every time when a function returns we should test whether it resulted in an error: this can lead to repetitive and tedious code. Combining the defer/panic/recover mechanism with closures can result in a far more elegant scheme that we will now discuss. However it is only applicable when all functions have the same signature, which is rather restrictive. A good example of its use is in web applications, where all handler functions are of the following type:</span></div><div class="MsoNormal"><span class="Apple-style-span" style="font-size: x-small;"> </span><span class="Apple-style-span" style="font-family: Consolas; font-size: 11px;">func handler1(w http.ResponseWriter, r *http.Request) { … }</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;">Suppose all functions have the signature: </span><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">func f(a type1, b type2)<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;">The number of parameters and their types is irrelevant. <o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;">We give this type a name: </span><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">fType1 =</span><span lang="EN-US" style="font-size: 10pt;"> </span><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">func f(a type1, b type2)<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;">Our scheme uses 2 helper functions:<o:p></o:p></span></div><div class="MsoListParagraphCxSpFirst" style="margin-left: 37.5pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -36.0pt;"><span lang="EN-US" style="font-size: 10pt;">i)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">check</span><span lang="EN-US" style="font-size: 10pt;">: a function which tests whether an error occurred, and panics if so:<o:p></o:p></span></div><div class="MsoListParagraphCxSpLast" style="margin-left: 37.5pt; mso-add-space: auto;"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt; text-indent: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">func check(err os.Error) { if err != nil { panic(err) } }<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoListParagraph" style="margin-left: 37.5pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -36.0pt;"><span lang="EN-US" style="font-size: 10pt;">ii)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">errorhandler</span><span lang="EN-US" style="font-size: 10pt;">: this is a wrapper function. It takes a function fn of our type </span><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">fType1 </span><span lang="EN-US" style="font-size: 10pt;">and returns such a function by calling fn. However it contains the defer/recover mechanism, outlined in § 13.3<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="margin-left: 70.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">func errorHandler(fn fType1) fType1 {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 70.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> return func(a type1, b type2) {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 70.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> defer func() {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 70.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> if e, ok := recover().(os.Error); ok {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 106.2pt; text-indent: 35.4pt;"><span class="apple-style-span"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">log.Printf("run time panic: %v", err)<o:p></o:p></span></span></div><div class="MsoNormal" style="margin-left: 70.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 70.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> }()<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 70.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> fn(a, b)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 70.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 70.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">}<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="margin-left: 35.25pt;"><span lang="EN-US" style="font-size: 10pt;">When an error occurs it is recovered and printed on the log; apart from simply printing the application could also produce a customized output for the user by using the template package (§ 15.6).<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;">The check() function is used in every called function, like this:<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">func f1(a type1, b type2) {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> …<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> f, _, err := // call function/method <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> check(err)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> t, err := // call function/method<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> check(err)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> _, err2 := // call function/method<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> check(err2)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> …<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">}<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;">The main() or other caller-function should then call the necessary functions wrapped in errorhandler, like this:<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">func main() {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> errorHandler(f1)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> errorHandler(f2)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> …<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">}<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;">Using this mechanism all errors are recovered and the error-checking code after a function call is reduced to </span><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">check(err).</span><span lang="EN-US" style="font-size: 10pt;">In this scheme different error-handlers have to be used for different function types; they could be hidden inside an error-handling package. Alternatively a more general approach could be using a slice of empty interface as parameter and return type.</span><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"><o:p></o:p></span></div>Ivohttp://www.blogger.com/profile/03262836162946789511noreply@blogger.com0tag:blogger.com,1999:blog-5896434103024473561.post-13310709373426255252011-10-28T04:47:00.000-07:002011-10-28T04:47:56.621-07:00Using memoization for performance<div class="MsoNormal"> <span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US;"> When doing heavy computations one thing that can be done for increasing performance is not to repeat any calculation that has already been done and that can/must be reused. Instead cache the calculated value in memory, which is called <i>memoization</i>. A great example of this is the calculation of the Fibonacci series:<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US;">to calculate the n-th Fibonacci number, you need the 2 preceding ones, which normally have already been calculated. If you do not stock the preceding results, every higher Fibonacci number results in an ever greater avalanche of recalculations, which is precisely what the following program does:<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b><u><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;">1<sup>st</sup> version:<o:p></o:p></span></u></b></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-family: Consolas; font-size: 8.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;">package</span><span style="font-family: Consolas; font-size: 8.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> main<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-family: Consolas; font-size: 8.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;">import</span><span style="font-family: Consolas; font-size: 8.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> (<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-family: Consolas; font-size: 8.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> "fmt"<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> "time"<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;">)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;">func</span><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> main() {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> result := 0<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> start := time.Nanoseconds()<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> for i:=0; i <= 25; i++ {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> result = fibonacci(i) <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> fmt.Printf("fibonacci(%d) is: %d\n", i, result)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> end := time.Nanoseconds()<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> fmt.Printf("the calculation took this amount of time: %f\n", float32(end - start)/1000000000) <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-bidi-font-weight: bold; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;">func</span><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> fibonacci(n int) (res int) {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> if n <= 1 {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> res = 1<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> } else {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> res = fibonacci(n-1) + fibonacci(n-2)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;"> return<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: NL-BE;">}<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US;">Simple stock the n-th Fibonacci number in an array at index n, and before calculating a fibonnaci-number, first look in the array if it has not yet been calculated. <o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US;">This principle is applied in the 2<sup>nd</sup> version; the performance gain is astounding, time both programs for the calculation up to the 40<sup>th</sup> Fibonnaci number:<o:p></o:p></span></div><div class="MsoNormal" style="text-indent: 35.4pt;"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US;"> normal: the calculation took this amount of time: 4.730270 s<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US;"> with memoization: the calculation took this amount of time: 0.001000 s<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US;">In this algorithm memoization is obvious, but it can often be applied in other computations as well, perhaps using maps instead of arrays or slices.<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b><u><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;">2<sup>nd</sup> version:<o:p></o:p></span></u></b></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;">package main<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;">import (<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> "fmt"<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> "time"<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;">)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;">const LIM = 41<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;">var fibs [LIM]uint64<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;">func main() {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> var result uint64 = 0<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> start := time.Nanoseconds()<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> for i:=0; i < LIM; i++ {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> result = fibonacci(i) <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> fmt.Printf("fibonacci(%d) is: %d\n", i, result)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> end := time.Nanoseconds()<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> fmt.Printf("the calculation took this amount of time: %f\n", float32(end - start)/1000000000) <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;">func fibonacci(n int) (res uint64) {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> // memoization: check if fibonacci(n) is already known in array:<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> if fibs[n] != 0 {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> res = fibs[n]<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> return<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> if n <= 1 {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> res = 1<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> } else {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> res = fibonacci(n-1) + fibonacci(n-2)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> fibs[n] = res<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US;"> return<o:p></o:p></span></div><span lang="EN-US" style="font-family: Consolas; font-size: 8.0pt; mso-ansi-language: EN-US; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;">}</span><u><span lang="EN-US" style="font-family: Calibri, sans-serif; font-size: 11pt;"><br clear="all" style="mso-special-character: line-break; page-break-before: always;" /></span></u>Ivohttp://www.blogger.com/profile/03262836162946789511noreply@blogger.com0tag:blogger.com,1999:blog-5896434103024473561.post-71331624326542715402011-09-24T06:17:00.000-07:002011-09-24T06:17:35.770-07:00Comparing the performance of Go on Windows and Linux.<div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;">I measured the performance of a simple Go channel benchmarking program on Windows versus Linux on the same system with as processor an Intel Core 2 Duo (T9300 2.5GHz) and 4 GB of memory.<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;">The Windows OS is a 64 bit Windows 7 Professional; the Linux OS is a 64 bit Linux Ubuntu 11.04 (Natty).<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;">The Linux Go release was: 6g release .r60 (9481).<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;">The Windows Go releases are: 8g release .r60 (9684) and 6g version weekly.2011-07-07 (9153+).<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;">I used the following program:<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">package main<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">import (<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> "fmt"<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> "testing"<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> "runtime"<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">func main() {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> runtime.GOMAXPROCS(1) // runtime.GOMAXPROCS(2)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> fmt.Println(" sync", testing.Benchmark(BenchmarkChannelSync).String())<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> fmt.Println("buffered", testing.Benchmark(BenchmarkChannelBuffered).String())<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">func BenchmarkChannelSync(b *testing.B) {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> ch := make(chan int)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> go func() {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> for i := 0; i < b.N; i++ {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> ch <- i<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> close(ch)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> }()<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> for _ = range ch {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">func BenchmarkChannelBuffered(b *testing.B) {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> ch := make(chan int, 128)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> go func() {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> for i := 0; i < b.N; i++ {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> ch <- i<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> close(ch)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> }()<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> for _ = range ch {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-family: Consolas; font-size: 8pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-size: 10pt;">These properties were compared:<o:p></o:p></span></div><div class="MsoListParagraphCxSpFirst" style="margin-left: 53.4pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 10pt;">1)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><span lang="EN-US" style="font-size: 10pt;">A synchronous channel versus a buffered channel<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 53.4pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 10pt;">2)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><span lang="EN-US" style="font-size: 10pt;">The value of GOMAXPROCS (1 versus 2, with value 2 both cores should be used)<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 53.4pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 10pt;">3)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><span lang="EN-US" style="font-size: 10pt;">Windows performance versus Linux<o:p></o:p></span></div><div class="MsoListParagraphCxSpLast" style="margin-left: 53.4pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 10pt;">4)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><span lang="EN-US" style="font-size: 10pt;">On Windows: a 32 bit Go-compiled program versus a 64 bit program.<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-size: 10pt;">The number of measurements for each result was between 4 and 5 x 10<sup>6 </sup> ; each result gives how many nanoseconds one operation took.<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.4pt;"><br />
</div><div class="MsoNormal" style="margin-left: 35.4pt;"><span lang="EN-US" style="font-size: 10pt;">Here are the results in ns/op: </span><br />
<span lang="EN-US" style="font-size: 10pt;"></span><br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; margin-left: 35.4pt; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;"><tbody>
<tr> <td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><br />
</div></td> <td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">GOMAXPROCS<o:p></o:p></span></div></td> <td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Synchronous<o:p></o:p></span></div></td> <td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">buffered<o:p></o:p></span></div></td> </tr>
<tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Windows (8g)<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">1<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">428<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">180<o:p></o:p></span></div></td> </tr>
<tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><br />
</div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">2<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">3577<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">3762<o:p></o:p></span></div></td> </tr>
<tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Windows (6g) <span> </span><o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">1<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">426<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">179<o:p></o:p></span></div></td> </tr>
<tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><br />
</div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">2<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">3603<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">4000<o:p></o:p></span></div></td> </tr>
<tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Linux(6g)<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">1<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">16642<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">210<o:p></o:p></span></div></td> </tr>
<tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><br />
</div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">2<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">17625<o:p></o:p></span></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 115.15pt;" valign="top" width="154"> <div class="MsoNormal"><span lang="EN-US" style="font-size: 10.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">212<o:p></o:p></span></div></td> </tr>
</tbody></table><br />
<span class="Apple-style-span" style="font-size: 13px;"><br />
</span><br />
<span class="Apple-style-span" style="font-size: 13px;">We can see the following:</span></div><div class="MsoListParagraphCxSpFirst" style="margin-left: 53.4pt; mso-add-space: auto; mso-list: l1 level1 lfo3; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 10pt;">1)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><span lang="EN-US" style="font-size: 10pt;">A <u>buffered channel performs better than a nonbuffered channel</u> as is to be expected:<o:p></o:p></span></div><div class="MsoListParagraphCxSpLast" style="margin-left: 70.8pt; mso-add-space: auto;"><span lang="EN-US" style="font-size: 10pt;">2.4x better on Windows (8g and 6g) <o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;"> 81x better on Linux<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoListParagraphCxSpFirst" style="margin-left: 53.4pt; mso-add-space: auto; mso-list: l1 level1 lfo3; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 10pt;">2)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><u><span lang="EN-US" style="font-size: 10pt;"> Influence of GOMAXPROCS 1 versus 2</span></u><span lang="EN-US" style="font-size: 10pt;">:<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 53.4pt; mso-add-space: auto;"><u><span lang="EN-US" style="font-size: 10pt;">On Windows (8g and 6g)</span></u><span lang="EN-US" style="font-size: 10pt;"> this did not behave as expected: the nonbuffered channel performed 8.4x worse for GOMAXPROCS=2 versus 1, and the buffered channel even 21.5x worse. Moreover buffering with GOMAXPROCS=2 even gives a slightly worser performance than the synchronous channel, in contrast to 1)!<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 53.4pt; mso-add-space: auto;"><u><span lang="EN-US" style="font-size: 10pt;">On Linux</span></u><span lang="EN-US" style="font-size: 10pt;"> also the results for GOMAXPROCS=2 are almost the same than value 1 (in fact very slightly worse). There is no improvement with increasing GOMAXPROCS.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 53.4pt; mso-add-space: auto;"><br />
</div><div class="MsoListParagraphCxSpLast" style="margin-left: 53.4pt; mso-add-space: auto; mso-list: l1 level1 lfo3; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 10pt;">3)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><u><span lang="EN-US" style="font-size: 10pt;"> Linux versus Windows</span></u><span lang="EN-US" style="font-size: 10pt;">: <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 53.4pt;"><span lang="EN-US" style="font-size: 10pt;">Windows performs slightly better for buffered channels and much better (39 x) for synchronous channels; I don’t know a reason for the latter.<o:p></o:p></span></div><div class="MsoListParagraphCxSpFirst" style="margin-left: 53.4pt; mso-add-space: auto;"><br />
</div><div class="MsoListParagraphCxSpLast" style="margin-left: 53.4pt; mso-add-space: auto; mso-list: l1 level1 lfo3; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 10pt;">4)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><u><span lang="EN-US" style="font-size: 10pt;">Windows 8g versus Windows 6g</span></u><span lang="EN-US" style="font-size: 10pt;">: they have the same performance.<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;"> We can conclude for this kind of problem (filling and reading a channel):<o:p></o:p></span></div><div class="MsoListParagraphCxSpFirst" style="margin-left: 53.25pt; mso-add-space: auto; mso-list: l2 level1 lfo4; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 10pt;">-<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><i><span lang="EN-US" style="font-size: 10pt;">Buffered channels perform better than synchronous channels (much better on Linux)<o:p></o:p></span></i></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 53.25pt; mso-add-space: auto; mso-list: l2 level1 lfo4; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 10pt;">-<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><i><span lang="EN-US" style="font-size: 10pt;">Increasing GOMAXPROCS is not useful here; the task being divided over the 2 cores creates an immense overhead.<o:p></o:p></span></i></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 53.25pt; mso-add-space: auto; mso-list: l2 level1 lfo4; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 10pt;">-<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><i><span lang="EN-US" style="font-size: 10pt;">Windows performs on par with Linux, and even much better for synchronous channels.<o:p></o:p></span></i></div><div class="MsoListParagraphCxSpLast" style="margin-left: 53.25pt; mso-add-space: auto; mso-list: l2 level1 lfo4; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 10pt;">-<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span><i><span lang="EN-US" style="font-size: 10pt;">Windows 8g performs the same as Windows 6g.<o:p></o:p></span></i></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 10pt;"> <o:p></o:p></span></div>Ivohttp://www.blogger.com/profile/03262836162946789511noreply@blogger.com0tag:blogger.com,1999:blog-5896434103024473561.post-4676033760322674742011-08-14T03:11:00.000-07:002011-08-17T03:24:40.854-07:00Why Go ?<div class="MsoNormal"><span lang="EN-US" style="font-size: 12pt;">After all, we have C and C++ when we need performance, Java and .NET for complex business oriented projects, Python and Ruby for nimble and flexible applications. Why should there be any need for another language? <o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 12pt;">Because C, our main system language on which nearly all other languages are built, is more than 40 years old and is getting less and less adapted to our distributed, networked and multicore computing world. </span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 12pt;">Go is an attempt to make a new foundation for the coming computing era, by proposing a C for the 21<sup>st</sup> century. Such an immense undertaking could only be successful when initiated by a team of distinguished software engineers and backed up by a big company. </span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 12pt;">And that is the case: the designers of Go are renowned software pioneers, creators and co-creators of Unix, C, Unicode and the Java hotspot compiler, namely Ken Thompson, Rob Pike and Robert Griesemer. The backing company is Google Inc., which has, considering its immense software and hardware infrastructure, a big business case for a language which could improve upon C++, Python and Java: and indeed Go is already in use within Google itself since May 2010.<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 12pt;">Go is not a completely new or experimental language, instead it combines good things from different existing languages and software engineering principles, thereby improving on many of the shortcomings of the above mentioned languages.<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 12pt;">Let’s make this clear with a few arguments:<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-size: 12pt;"><br />
</span></div><div class="MsoListParagraphCxSpFirst" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><b><span lang="EN-US" style="font-size: 12pt;">1)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span></b><span lang="EN-US" style="font-size: 12pt;">Go is completely <i>free and open source</i>, so you don’t owe Google anything (except your gratitude if you are so inclined); it isn’t bound to Google and could grow also outside of it (just like C was not bound to Bell Labs). It runs on Linux, OS X and Windows.<o:p></o:p></span></div><div class="MsoListParagraphCxSpFirst" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 12pt;"><br />
</span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><b><span lang="EN-US" style="font-size: 12pt;">2)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span></b><span lang="EN-US" style="font-size: 12pt;">An important design point is <i>simplicity</i>: Go has a familiar syntax for developers accustomed to C++, Java, and .NET, but it is very much cleaned up, made <i>concise</i>, less keywords and constructs but more powerful. The code layout obeys a few simple rules and is imposed by a formatting tool (gofmt), so no fruitless discussions about code layout styles anymore, and the code is very readable, which is of the utmost importance in large projects.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 12pt;"><br />
</span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><b><span lang="EN-US" style="font-size: 12pt;">3)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span></b><span lang="EN-US" style="font-size: 12pt;">It is a <i>statically typed language</i>, so most of the infamous runtime errors of dynamic languages are caught at compile time. It compiles to native code, with execution speeds at this moment superseding Python by a factor of 5 to 100, nearing C++ speeds within a factor of 2, and still improving. And it compiles extremely fast, contrary to the well known heavy compilations of C++ projects. So again well suited for large demanding projects, and accelerating the development life cycle.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 12pt;"><br />
</span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><b><span lang="EN-US" style="font-size: 12pt;">4)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span></b><span lang="EN-US" style="font-size: 12pt;">Go doesn’t allow you memory tricks in programming, saving the programmer from this league of errors. Programs execute in a Go <i>runtime</i>, which is not as heavy as the Java or .NET virtual machines, but which amongst other things takes care of garbage collection, so frees you from memory management and leaks. And it gives you <i>reflection</i> capabilities !<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 12pt;"><br />
</span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><b><span lang="EN-US" style="font-size: 12pt;">5)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span></b><span lang="EN-US" style="font-size: 12pt;">At the same time Go does some <i>type inferencing</i> like dynamic languages, thereby reducing the clutter of declaration statements and giving it a Python-like feel.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 12pt;"><br />
</span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><b><span lang="EN-US" style="font-size: 12pt;">6)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span></b><span lang="EN-US" style="font-size: 12pt;">Go is <i>object oriented</i>, but not in the <i>class</i>ic style of C++ / Java / .NET. Instead of a heavy weight class-hierarchy system, it uses lightweight but powerful types and exploits the interface principle to its extreme. This makes for reduced and very general library code.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 12pt;"><br />
</span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><b><span lang="EN-US" style="font-size: 12pt;">7)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span></b><i><span lang="EN-US" style="font-size: 12pt;">Functions are first class citizens</span></i><span lang="EN-US" style="font-size: 12pt;"> in Go, not as much as in the typical functional languages like Haskell, F# or Scala, but higher order functions and closures are used widely in Go-code, also increasing its abstracting powers.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 12pt;"><br />
</span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><b><span lang="EN-US" style="font-size: 12pt;">8)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span></b><span lang="EN-US" style="font-size: 12pt;">Go is built from the ground up for <i>concurrent and parallel execution</i> on multicore and networked machines. Built in are goroutines and channels, the tools which realize a programming paradigm based on communication, not on locking.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 12pt;"><br />
</span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><b><span lang="EN-US" style="font-size: 12pt;">9)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span></b><span lang="EN-US" style="font-size: 12pt;">It is suited for <i>cloud programming</i>, being enabled in Google App Engine. At the same time it runs on ARM processors, making possible future smartphone applications.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><span lang="EN-US" style="font-size: 12pt;"><br />
</span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -18.0pt;"><b><span lang="EN-US" style="font-size: 10pt;">10)<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span></b><span lang="EN-US" style="font-size: 12pt;">Go has, certainly also because of its open source character, <i>a strong, lively and active community of contributors to the language</i>, building packages or projects in it or experimenting with it. Real life examples of usage of Go in other organizations can be found at </span><a href="http://go-lang.cat-v.org/organizations-using-go"><span lang="EN-US" style="font-size: 10pt;">http://go-lang.cat-v.org/organizations-using-go</span></a><span lang="EN-US" style="font-size: 10pt;"><o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="margin-left: 46.35pt; mso-add-space: auto;"><br />
</div><div class="MsoListParagraphCxSpLast" style="margin-left: 46.35pt; mso-add-space: auto;"><span lang="EN-US" style="font-size: 12pt;">Give it a try. On this blog will appear more means to guide you with that.<o:p></o:p></span></div><div class="MsoNormal"><br />
</div>Ivohttp://www.blogger.com/profile/03262836162946789511noreply@blogger.com0