Use Ocaml, save the world
(Note: this post is written in a tongue-in-cheek manner; take it too seriously at your own peril).
Since this blog is syndicated in the Ocamlcore Planet, readers may be wondering about the implications for our favourite language of the coming energy crisis I just wrote about. And in general, just how well are different computer languages adapted to an energy-constrained economy?
There are two different factors to consider: a) how efficient is the language at converting CPU cycles into useful work, and b) how efficient is the language at converting programmer time into useful programmes.
The importance of the first factor should be self-evident. If not, note that computers consume an increasing percentage of our energy, and that data centres all over the world also require a significant amount of power. Moreover, there is a wide disparity in the amount of time different languages require to complete the same task. This difference boils down to different approaches to programme execution (compiled languages tend to be more efficient than interpreted ones) and the quality of the code generated by compilers. The Computer Language Shootout, though not without its flaws, provides some ballpark figures on the efficiency of different languages. As you can see, Ocaml fares very well on the existing benchmarks.
The second factor, though it may not be obvious at first sight, may indeed be even more relevant to this discussion. Programmer time requires energy not only to sustain the Homo sapiens specimen that does the programming, but also because programming is to a large extent done in front of an energy-hungry computer. Therefore, by making the programmer more productive, a computer language can result in significant energy savings.
Measuring language productivity is a difficult task. Nevertheless, I would like to posit that the availability of a strong static type checker such as Ocaml's — one that catches most common mistakes at compile-time — is a plus in this regard. Even more so if we consider runtime errors as a loss of productivity. Another good proxy for language productivity is indicated by the terseness of its programmes. Again, the Computer Language Shootout may be of assistance.
So, how well does Ocaml fare when these two factors are taken into account? Very well, I am pleased to say. In fact, using some reasonable parametrisation, the results of the Shootout show Ocaml as the top rated language. We can therefore conclude that Ocaml will also have a role to play in saving civilisation from an energy crisis.

You should also take into consideration "how much the language is able to be understood and processed by a computer". In other word, how much lines of the written program can be reprocessed by a computer to produced a more energy efficient version for example.
This is a general "legacy code" problem. For example, COBOL is not a regular language and there is at least 10 to 20% of written COBOL code that need to be reprocessed by hand to migrate the code from a mainframe to a UNIX, for example. The cost of this migration is directly proportional to the time spent to write the initial program. For 10% of lines not understood in the initial program, you will spent ~15% of the initial time to rewrite your program.
This parameters should be taken into account using "computer tersness" of the language, ability to find efficient programmers and number of bugs left in the code.
"computer tersness" defines how much a computer reading your code will understand your aim...
Sylvain Le Gall
(not so tongue in cheek)
Reply to this
interesting article. One question though: I think when you speak on Ocamls performance you always mean native compiled programs right? Isn't there a problem regarding bigger applications because there you often have to load libraries? For example mod_caml or the ocsigen webserver isn't this bytecode compiled? In the shout out example you refering to, Ocaml comes after ruby if compiled to bytecode! http://shootout.alioth.debian.org/debian/benchmark.php?test=all&lang=all&calc=Calculate&xfullcpu=1&xmem=0&xloc=5&binarytrees=1&chameneosredux=1&fannkuch=1&fasta=1&knucleotide=1&mandelbrot=1&nbody=1&nsieve=1&nsievebits=1&partialsums=1&pidigits=1&recursive=1®exdna=1&revcomp=1&spectralnorm=1&hello=0&sumcol=1&threadring=1
Reply to this
Hi, Well, when performance matters, simply use native code! As you noted, with Ocaml 3.10, it is not possible to dynamically load libraries when using native code. However, version 3.11 fixes this, so there's nothing holding you back...
Reply to this