Time

time ./TimingTest

real 0m3.503s

user 0m3.492s

sys 0m0.004s

GHCI

TimeIt

timeIt :: IO a -> IO a -- | Wrap an IO computation so that it prints out the execution time

timeItT :: IO a -> IO (Double, a)Source -- | Wrap an IO computation so that it returns execution time is seconds as well as the real value.

Start

Result: 5736396

CPU time: 8.22s

Criterion

estimating clock resolution...

mean is 3.760062 us (160001 iterations)

found 3006 outliers among 159999 samples (1.9%)

2461 (1.5%) high severe

estimating cost of a clock call...

mean is 98.08812 ns (28 iterations)

found 4 outliers among 28 samples (14.3%)

4 (14.3%) low severe

Some times ago i encountered with question: How to get function execution time in Haskell program? I asked this question at StackOverflow , and got some useful answers. Here i will try to describe how to do it.For example we have simple haskell program which will calculate sum of prime numbers which are between 0 and 10000. Something like this:Yes. It's not the best implementation of prime numbers, but it's not important at the current moment. Let's see what we have for checking execution time.First of all, the simplest method to get execution time iscommand. Compile our source code and execute:We must get something like this:Second method is the simplest things is to just addin ghci before function execution. Of course it's not the best method, because functions run much slower in ghci.In third method we will use TimeIt library by Lennart Augustsson. Very little, but useful library with simple API. It consist only from two functions:andWill remake ourfunction as:and will get something like this: Criterion - is a library provides a powerful but simple way to measure software performance by Bryan O'Sullivan. For using it, will remake again ourfunction as:after our program running we got:If you'll have any questions/suggestions write me in comments or ping me at twitter: @0xAX