Hello - <div><br></div><div>I've been trying to measure execution time for some code I'm running with the StateT monad transformer. </div><div><br></div><div>I have a function f :: StateT MyState IO a</div><div><br>
</div><div>Now, I measure the time it takes to run an invocation of this function from beginning to end, i.e.</div><div><br></div><div>f = do</div><div> t0 <- getCurrentTime</div><div> stuffToDo</div><div> t1 <- getCurrentTime</div>
<div> liftIO $ putStrLn (show $ diffUTCTime t1 t0)</div><div><br></div><div>And also measure like this:</div><div><br></div><div>g :: IO</div><div>g = do </div><div> t0 <- getCurrentTime</div><div> (val,newState) <- runStateT f initialState</div>
<div> t1 <- getCurrentTime</div><div> putStrLn $ "outside: " ++ (show $ diffUTCTime t1 t0)</div><div><br></div><div><br></div><div>Curiously, the times reported for "outside" are about 5-8 times as long.</div>
<div>I should probably note that stuffToDo calls itself a few hundred times (and uses liftIO once per loop).</div><div><br></div><div>Anyone with ideas on why runStateT apparently has so much overhead?</div><div><br></div>
<div>By the way I'm using ghc-6.10.4 and Control.Monad.Trans.State.Strict.</div><div><br></div><div>Thanks for any suggestions or advice.</div><div>Thomas</div>