MrD
MrD

Reputation: 5084

Haskell Collect Runtime of Function

I have a Haskell function which I need to collect runtime for over a series of inputs running 0 to 1,000,000 in steps of 100. Now, I would usually set ghci to :set +s, but I'm not really keen on manually running the script thousands of times.

I was wondering if there was any way I could code a Haskell function to return the runtime of another function.

Thanks Dario

Upvotes: 0

Views: 100

Answers (1)

Carl
Carl

Reputation: 27023

There's the entire criterion package for doing this. As opposed to ghci, it runs the code with optimizations, too.

Start with the Criterion.Main module.

Criterion isn't well-suited to collecting data for each of a million data points, but it could be used that way.

I'd certainly trust its results way more than the results of a single timing for each of million data points. But it would take a while to collect a million results.

Upvotes: 3

Related Questions