1

I'm messing around with binary trees, and I'm trying to get a very rough benchmark of a few functions using GHCi. I only want to get the time required to evaluate the test functions; not how long it takes to fold the tree. If I have:

"ghci>" let tR = tFromListR [1..1000000] --I want to force this to evaluate
"ghci>" tMax tR --I want to get the time required to evaluate this

How can I force evaluation of the first line (so the generation time isn't included)? I could obviously just type "tR", which would print the massive tree, but it outputs rather slowly. It would probably take an hour to 2 to completely print.

(Yes I know GHCi will be slower then fully compiled code. I'm looking for relative times)

  • Doesn't tFromListR yield each value only as it is needed anyway? – Robert Harvey Sep 23 '14 at 23:33
  • Yes, which is the problem. I want it to be evaluated fully before it's needed. – Carcigenicate Sep 24 '14 at 1:20
  • 1
    Not to be too blunt about it, but the measurement you're describing is almost certainly useless. If you really need the time without the evaluation, just factor out the time each individual value evaluation takes. – Robert Harvey Sep 24 '14 at 4:58
  • Yes, after a little sleep I realized that the build time should be consistent, so I can just minus the times. I was afraid that the tree would be saved after the first test in a thunk, which would make the second test take less time, but I could just kill/reload GHCi to ensure that that isn't the case. Sorry. Wasn't thinking. – Carcigenicate Sep 24 '14 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.