I haven't looked at the code much yetBut might want to consider strictness 😎--
Sent from an expensive device which will be obsolete in a few months
CaseyOn Thu, Jul 5, 2018, 7:01 PM Awsaf Rahman, <awsafrahman1704@gmail.com> wrote:______________________________Hello everyone!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.Here is the implementation in Haskell:{-# LANGUAGE OverloadedStrings #-}{-# LANGUAGE BangPatterns #-}import Control.Exceptionimport Formattingimport Formatting.Clockimport System.Clockimport Control.DeepSeqmergesort [] = []mergesort [x] = [x]mergesort xs = let (lhalf, rhalf) = splitAt (length xs `div` 2) xsin merge' (mergesort lhalf) (mergesort rhalf)merge' lhalf rhalf = merge lhalf rhalf []merge [] [] acc = reverse accmerge [] y acc = reverse acc ++ ymerge x [] acc = reverse acc ++ xmerge (l:ls) (r:rs) acc| l < r = merge ls (r:rs) (l:acc)| otherwise = merge rs (l:ls) (r:acc)toList :: String -> [Integer]toList input = read ("[" ++ input ++ "]")main = dofile <- getLinecontents <- readFile filelet !unsortedlist = (toList contents)start <- getTime Monotonicevaluate(force (mergesort unsortedlist))end <- getTime Monotonicfprint (timeSpecs % "\n") start end
What am I doing wrong?_________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners