C not the most efficient Programming Language?
March 27, 2007 3 Comments
My friend sent me this blog post which claims that C is not the most efficient programming language. The basis of the author’s claim is that in most modern computing systems careful hand-crafted optimizations are difficult to do and one has to rely on the prowess of the compiler to produce efficient executables. C, which enables complex pointer arithmetic, makes it very difficult for the compiler to do some optimizations because its free-flowing memory access pattern leads to complications in doing alias analysis. This essentially means that it is difficult to figure out if two pointers can point to the same region in memory in C. If we can figure out that the memory foot prints of two pointers are disjoint, the compiler might be able to step in and do some efficient optimizations, which it is unable to do.
The post makes for interesting reading. The author speaks about an experiment with the implementation of an LCS algorithm on OCaml, C and other languages and claims that OCaml outperformed C.
Food for thought indeed. However, I was not sure if employing good pointer aliasing analysis algorithms in his simple case and performing better optimizations would have enabled C to outperform. His one example may not be representative of all programs and there are too many other variables that have not been studied.