Skip to content

Instantly share code, notes, and snippets.

@autotaker
Created December 22, 2015 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save autotaker/082402e29104b2f21a6d to your computer and use it in GitHub Desktop.
Save autotaker/082402e29104b2f21a6d to your computer and use it in GitHub Desktop.
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Control.DeepSeq
import Data.Time
import Control.Exception(evaluate)
import System.IO
import Text.Printf
import Prelude hiding(log)
import Data.List(sort)
log :: String -> IO UTCTime
log xs = do
t <- getCurrentTime
hPrintf stderr "[%s] %s\n" (show t) xs
return t
main :: IO ()
main = do
t0 <- log "begin"
xs <- map (fst . fromJust . B.readInt) . B.words <$> B.getContents
evaluate (rnf xs)
t1 <- log "parse done"
let ls = sort xs
evaluate (rnf ls)
t2 <- log "sort done"
let dt = diffUTCTime t2 t1
_ <- log $ printf "Sorting: %s" (show dt)
putStr $ unlines $ map show ls
t3 <- log "output done"
_ <- log $ printf "Elapsed Time: %s" (show (diffUTCTime t3 t0))
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment