Hello!
I saw a question on StackOverflow about the difference between isAlpha and
isLetter today. One of the answers stated that the two functions are
interchangeable, even though they are implemented differently.
I decided to find out whether the difference in implementation influences
performance, and look what I found:
import Criterion.Main
import Data.Char
fTest name f list = bgroup name $ map (\(n,c) -> bench n $ whnf f c) list
tests = [("latin", 'e'), ("digit", '8'), ("symbol", '…'), ("greek", 'λ')]
main = defaultMain [fTest "isAlpha" isAlpha tests,
fTest "isLetter" isLetter tests]
produces this table (times are in nanoseconds):
latin digit symbol greek
----- ----- ------ -----
isAlpha | 156 212 368 310
isLetter | 349 344 383 310
isAlpha is twice as fast on latin inputs! Does it mean that isAlpha should
be preferred? Why isn’t isLetter defined in terms of isAlpha in Data.Char?
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe