Skip to content

Instantly share code, notes, and snippets.

@wunki
Created May 23, 2014 20:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wunki/9361c2d0172036bfe53b to your computer and use it in GitHub Desktop.
Save wunki/9361c2d0172036bfe53b to your computer and use it in GitHub Desktop.
module Main where
import System.Environment (getArgs)
import qualified Data.ByteString.Lazy as L
import Data.Word
{-
- Test to see how fast we can process an 1GB binary file.
- From the blog post: http://jvns.ca/blog/2014/05/12/computers-are-fast/
-
-}
-- Result: stack space overflow...
addBytes :: [Word8] -> Word8
addBytes [] = 0
addBytes (x:xs) = x + addBytes xs
-- Result: stack space overflow...
addBytes' :: [Word8] -> Word8
addBytes' = foldr (+) 0
-- Result: 18 seconds
addBytes'' :: [Word8] -> Word8
addBytes'' = sum
main :: IO ()
main = do
args <- getArgs
let filename = head args
fc <- L.readFile filename
print $ addBytes'' $ L.unpack fc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment