Erik said:
Of course they are, at the very least they are not independent from the
specific implementation of the raytracer (in both C++ and OCaml). A
better programmer might implement the same raytracer in a more efficient
way (in both languages). You can never compare the efficiency of two
languages like that, only the efficiencies of implementations of a
problem in different languages.
Absolutely. I wasn't talking about the ray tracer though, but two different
implementations of Smoke:
http://www.ffconsultancy.com/products/smoke_vector_graphics/
The two implementations have different worst-case complexities, which is
quite common for C++ vs OCaml comparisons because C++ tends to use arrays
and avalanche deallocation from destructors whereas OCaml often uses trees
(much more incremental friendly) and has an incremental garbage collector
that distributes deallocations evenly over time.
You can get some of the bad worst case performance (but typically better
average case performance) in OCaml by using hash tables instead of trees.
Doing the converse in C++ (which is required for soft real-time
applications) is very hard though. You basically need to rewrite all of the
memory allocation and deallocation routines yourself, replace the STL
allocators, but even then you cannot perform heap compaction because C++
exposes pointers to the programmer, so your heap becomes fragmented and
you've just moved to another problem.
We spent many years trying to improve the worst case performance of our C++
implementation and we basically failed. When we tried translating the
program into OCaml as a test, we were pleasantly surprised to find that the
worst case performance for typical use was 5x faster, simply as a
side-effect of using a language with a good garbage collector. This is the
result of the OCaml garbage collector (the result of 10+ years of research)
using better algorithms than anything we had managed to implement.