[Haskell-cafe] Timing execution of individual functions in ghci?
Magnus Therning
magnus at therning.org
Thu Oct 23 14:04:45 UTC 2014
On Wed, Oct 22, 2014 at 12:48:53PM +0200, Daniel Trstenjak wrote:
>
> Hi Magnus,
>
>> When playing around with various implementations of a single
>> function it would be nice to time the execution. Is there some way
>> to do that easily from within GHCi?
>
> ghci normally only interprets your code, without much optimizations,
> so your timings might be quite misleading.
Well, it might be enough to confirm or disprove intuitions about time
complexity of an implementation; is it O(n) or O(n^2)? And that's
really what I'd like to see at a first step.
Given that all I'm interested in is relative timings it might even be
enough to do a rough comparison of two implementations too.
>> Or am I forced to look to criterion for that?
>
> I think so, if you want to trust your timings.
It's just a bit too much ceremony when all I want is to confirm that
"inserting in reversed order followed by a `reverse`" has less time
complexity than "repeated appending."
Of course the only way to get something I can take to the bank is
using criterion.
/M
--
Magnus Therning OpenPGP: 0xAB4DFBA4
email: magnus at therning.org jabber: magnus at therning.org
twitter: magthe http://therning.org/magnus
Heuristic is an algorithm in a clown suit. It’s less predictable, it’s more
fun, and it comes without a 30-day, money-back guarantee.
-- Steve McConnell, Code Complete
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141023/dc2dc43e/attachment.sig>
More information about the Haskell-Cafe
mailing list