<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>