Eccentric Developments


Raybench - Go (PLC pt.11)

Go is a programming language created by Google in 2007 by Robert Griesemer. It is a compiled language with static typing, embracing the imperative style of programming.

One of the main reasons for this language to exist, is as a replacement for C++, offering a simpler toolchain and more concise language constructs. With a more expressive syntax overall.

Results

Go version 1.6 was used for running the tests.

Compile time

How fast does the compiler takes to generate the binary.

$ time go build gorb.go

real	0m1.353s
user	0m1.180s
sys	0m0.120s

Compilation time is not as fast as I was expecting; it takes twice as much time as the GCC, and around the same time as node.js.

Running Time

$ time ./gorb

real    6m44.151s
user    6m35.732s
sys     0m4.144s

More than three times the running time of C, Go is not as fast as I was expecting, not for a language with so much hype online.

Code Metrics

Line count: 204 code, 64 blank, 268 total. File size: 5421 bytes.

The implementation is quite a bit more concise than C, but still behind OCaml.

General Thoughts

While more expressive than C, I didn't find the language to be much of a breakthrough, at least for this particular use case.

Vim automatically had binding with the language and give hints on good practices, also, the compiler wouldn't let you compile when you have unused variables; helping you with code clarity, which is nice.

One the problems I found had to do with floating point numbers, as the compiler doesn't automatically casts between 32 and 64 bit precision float numbers, forcing you to explicitly do the conversions, adding clutter to the code.

Also, I had this very weird problem that, while the program compiled and executed, the results where not correct. It took me a couple of hours of tinkering to finally find the problem, which was caused by the omission of a member while instantiating a variable of type ray.

The compiler simply wouldn't complain and resorted to initialise the omitted property to default values. This is a two-edged sword; it can help with code cleanness, but if you are carless (like I was), it can become a headache. In this regard, I prefer Haskell and OCaml, that wouldn't let you compile on those situations.

Talking about OCaml, in several occasions when doing the translation from C to Go, I found myself consulting back to OCaml, which was easier to read and follow.

Overall, Go isn't as good as I was expecting from all the comments around the Internet; while beign more expressive than C, generated binaries are not as fast as C or OCaml, and it's only about 10% faster than node.js v6.2.1; which doesn't bode that well for a compiled language. Sadly, the compiler didn't offer any optimisation flags that could be used to further reduce running time.

Follow

You can follow the development of this project on GitHub: https://github.com/niofis/raybench