3 ms·
> C++ is also 4x faster than Haskell in the second benchmark, giving further indication that the C is slow just because it is poorly written. That would imply
by mpyne 14y ago
> C++ is also 4x faster than Haskell in the second benchmark, giving further indication that the C is slow just because it is poorly written.
That would imply that the C version of the C++ code would be just as fast, if only it were not "poorly written".
However there are some types of code (including this kind) where having C++ available to generate the code for you makes it almost inherently faster than C.
You could certainly reimplement specific matrix operations for very specific types in C, but the C++ Eigen library does this all for you at compile time, and does it the best way for each combination of types and operations.
If you do this in C, even with macros everywhere, it's going to be much more difficult, especially since you can't (AFAIK) declare and discard temporary types within macros, though C11 at least allows you to refer generically to types within macros. The canonical example for this kind of disparity is C's qsort() vs. C++ templated sorts.
This is kind of the point to the paper. Performance of this sort is only possible in C++ if you're careful to follow the instructions provided with Eigen about using templated functions, and some very smart devs had to write Eigen in the first place. The Haskell code comes fairly close starting from the source code you'd write naïvely, and without tons of optimization on the stream fusion code generator.
- jules 14y agoIn general, you're absolutely right. For this particular benchmark, this is not the case. See here: https://news.ycombinator.com/item?id=5508948 https://news.ycombinator.com/item?id=5508948