4 ms·
Why are these simple Haskell text processing programs so much faster than in C?
- tome 14y agoAlso submitted to Haskell Reddit: http://www.reddit.com/r/haskell/comments/128j84/why_are_these_simple_text_processing_programs_so/ http://www.reddit.com/r/haskell/comments/128j84/why_are_thes...
- qznc 14y agoBecause they do not have to worry about locale. For a fair comparison the Haskell programs must be rewritten with a different toUpper function: http://hackage.haskell.org/packages/archive/text-icu/0.6.3.5/doc/html/Data-Text-ICU.html#v%3atoUpper http://hackage.haskell.org/packages/archive/text-icu/0.6.3.5... See also: http://stackoverflow.com/questions/12537377/in-haskell-how-can-i-uppercase-a-unicode-character-with-respect-to-current-local http://stackoverflow.com/questions/12537377/in-haskell-how-c...
- splinterofchaos 14y agoBecause they don't do the same thing. The Haskell code tests if that last char was a space and returns b or toupper(b). The C code checks if the current char is an alpha, then checks if word is set. That's a two branch algorithm. What mystifies me is why the C programmer didn't use the Haskell coder's algorithm, which is much more obvious. In my own tests, if you modify the C program to use the one-branch algorithm (just maintain a char called "last" instead of the bool "word"), the two run at the same speed.