I did consider strictness and that is why the execution time has come down from 16 seconds to 12 seconds! But I can't seem to find the issue anymore!_______________________________________________On Fri, Jul 6, 2018 at 4:06 AM, KC <kc1956@gmail.com> wrote: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
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners