I saw 3 functions to compute the length of a list on https://www.haskell.org/haskellwiki/Performance/Accumulating_parameter
len :: [a] -> Int
len [] = 0
len (x:xs) = len xs + 1
len' :: [a] -> Int -> Int
len' [] acc = acc
len' (x:xs) acc = len' xs (1 + acc)
len'' [] acc = acc
len'' (x:xs) acc = len'' xs $! (1 + acc)
In GHCi, function len is slowest and len'' is fastest. But when I compile it with GHC, function len is faster than len', Which means non tail-recursive function is faster than tail-recursive function. What's the reason for this?
Details:
len [1..10000000] : 3.05s
len' [1..10000000] 0 : 3.52s
len [1..50000000] : 13.67s
len' [1..50000000] 0 : 16.13s