Search code examples
haskelltimeprofilingexecutionmeasurement

How to get a program's running time in Haskell


How can I go about getting a program's running time through system time functions in Haskell? I would like to measure the execution time of a whole program and/or an individual function.


Solution

  • Assuming you don't just want to measure the total running time of your program, like so:

     $ time ./A
    

    Then you can time a computation a number of ways in Haskell:

    For more statistically sound measurement, consider

    Finally, in all cases, you need to think about lazy evaluation: do you want to measure the cost of fully evaluating whatever data you produce, or just to its outermost constructor?