-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.hs
More file actions
38 lines (34 loc) · 1.28 KB
/
Copy pathMain.hs
File metadata and controls
38 lines (34 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import System.Environment
import System.IO
import Control.Monad
import System.Process
import Control.Applicative
import Text.Printf
import Data.Time
sequenceWhileTrue [] = return ()
sequenceWhileTrue (m:ms) = do
r <- m
if r then m >> sequenceWhileTrue ms
else return ()
main = do
(x:xs) <- getArgs
hSetBuffering stdout NoBuffering
(_, Just hout, _, _) <-
createProcess (proc x xs) {std_out = CreatePipe}
hSetBuffering hout NoBuffering
sequenceWhileTrue $
((flip map) [1..] (\x -> do
((more,line0),time0) <- timeAction $ do
more <- not <$> hIsEOF hout
if more then do
hout' <- hGetLine hout
return (more,hout')
else return (more,"")
when more (putStrLn $ show x ++ ":" ++ printf "%f" (time0) ++ ":" ++ line0)
return more))
timeAction action = do
t1 <- getCurrentTime
g <- action
t2 <- getCurrentTime
let timeInUnits = (realToFrac $ diffUTCTime t2 t1 :: Float)
return (g,timeInUnits)