Writing a time function in Haskell

后端 未结 3 1441
北荒
北荒 2021-02-05 03:27

I’m new to Haskell and I’d like to be able to time the runtime of a given function call or snippet of code.

In Clojure I can use ‘time’:

user=> (time          


        
3条回答
  •  死守一世寂寞
    2021-02-05 04:24

    Please look at using the standard libraries for this:

    • Timing computations in Haskell
    • Criterion, possibly the best open source benchmarking/timing library in existence
    • About Criterion

    Just use criterion.


    A note on evaluation depth: laziness means you need to decide how much evaluation you want to have during your timing run. Typically you'll want to reduce your code to normal form. The NFData typeclass lets you do this via the rnf method. If evaluating to the outermost constructor is ok, use seq on your pure code to force its evaluation.

提交回复
热议问题