Hello - <div><br></div><div>I&#39;ve been trying to measure execution time for some code I&#39;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 &lt;- getCurrentTime</div><div>  stuffToDo</div><div>  t1 &lt;- 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 &lt;- getCurrentTime</div><div>  (val,newState) &lt;- runStateT f initialState</div>
<div>  t1 &lt;- getCurrentTime</div><div>  putStrLn  $ &quot;outside: &quot; ++ (show $ diffUTCTime t1 t0)</div><div><br></div><div><br></div><div>Curiously, the times reported for &quot;outside&quot; 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&#39;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>