Hacker News new | past | comments | ask | show | jobs | submit login

Because 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.



Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: