Writing a time function in Haskell

后端 未结 3 1442
北荒
北荒 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:10

    Haskell is lazily evaluated. If your expression doesn't have some side effect (as encoded in the IO monad or the like), then the program doesn't need to actually resolve the expression to a value, and so won't.

    To get meaningful numbers out of this, you might try timing print 4 and print expr and take the difference, in order to remove the overhead of string formatting and IO.

提交回复
热议问题