<div dir="auto">I haven't looked at the code much yet<div dir="auto">But might want to consider strictness ðŸ˜Ž<br><br><div data-smartmail="gmail_signature" dir="auto">--<br>Sent from an expensive device which will be obsolete in a few months<br>Casey</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 5, 2018, 7:01 PM Awsaf Rahman, <<a href="mailto:awsafrahman1704@gmail.com">awsafrahman1704@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello everyone! <div><br></div><div>I am trying to find out the execution time of mergesort for a list size of 1 million integers. I have done the same in Erlang as well and the execution time in Erlang was around 0.93 seconds. I have implemented the program in almost the same way in Haskell as well but for some reason the Haskell implementation is taking around 12 seconds which doesn't seem right. </div><div><br></div><div>Here is the implementation in Haskell: </div><div><br></div><div><div><b>{-# LANGUAGE OverloadedStrings #-}</b></div><div><b>{-# LANGUAGE BangPatterns #-}</b></div><div><b>import Control.Exception</b></div><div><b>import Formatting</b></div><div><b>import Formatting.Clock</b></div><div><b>import System.Clock</b></div><div><b>import Control.DeepSeq</b></div><div><b><br></b></div><div><b>mergesort [] = []</b></div><div><b>mergesort [x] = [x]</b></div><div><b>mergesort xs = let (lhalf, rhalf) = splitAt (length xs `div` 2) xs</b></div><div><b>  Â  Â  Â  Â  Â  Â  Â in merge' (mergesort lhalf) (mergesort rhalf)</b></div><div><b><br></b></div><div><b>merge' lhalf rhalf = merge lhalf rhalf []</b></div><div><b><br></b></div><div><b>merge [] [] acc = reverse acc</b></div><div><b>merge [] y acc = reverse acc ++ y</b></div><div><b>merge x [] acc = reverse acc ++ x</b></div><div><b><br></b></div><div><b>merge (l:ls) (r:rs) acc</b></div><div><b>  Â  Â  Â  | l < r = merge ls (r:rs) (l:acc)</b></div><div><b>  Â  Â  Â  | otherwise = merge rs (l:ls) (r:acc)</b></div><div><b><br></b></div><div><b>toList :: String -> [Integer]</b></div><div><b>toList input = read ("[" ++ input ++ "]")</b></div><div><b><br></b></div><div><b>main = do</b></div><div><b>  Â  file <- getLine</b></div><div><b>  Â  contents <- readFile file</b></div><div><b>  Â  let !unsortedlist = (toList contents)</b></div><div><b>  Â  start <- getTime Monotonic</b></div><div><b>  Â  evaluate(force (mergesort unsortedlist))</b></div><div><b>  Â  end <- getTime Monotonic</b></div><div><b>  Â  fprint (timeSpecs % "\n") start end</b><br><br><br>What am I doing wrong? </div></div></div>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank" rel="noreferrer">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>