Skip to content

Instantly share code, notes, and snippets.

@JamesMcMahon
Created November 8, 2015 00:36
Show Gist options
  • Save JamesMcMahon/7fdd0570853677048168 to your computer and use it in GitHub Desktop.
Save JamesMcMahon/7fdd0570853677048168 to your computer and use it in GitHub Desktop.
Haskell lazy performance test
#!/usr/bin/env runhaskell
maximum' :: (Ord a) => [a] -> a
maximum' [] = error "maximum of empty list"
maximum' [x] = x
maximum' (x:xs) = max x (maximum' xs)
main :: IO ()
main = do
-- print (maximum' [3, 5, 7, 3, 6])
print (maximum' [1..6543210])
#!/usr/bin/env python
# -*- coding: utf-8 -*-
print(max([i for i in range(6543210)]))
@JamesMcMahon
Copy link
Author

Why is the Python code so much faster? Most likely doing something wrong in the Haskell code just not familiar enough with the language to figure it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment