Evan Martin (evan) wrote in evan_tech,
Evan Martin

time profiling

In C, constructs like "while" and "for" are built into the language. In this fascinating history of Haskell they mention that in higher-level languages (Ruby is an example, too), these control-flow constructs are built as functions in the standard libraries, which makes function-based profiling not as useful:
... knowing that map consumes 20% of execution time is little help to the programmer—we need to know instead which occurrence of map stands for a large fraction of the time. Likewise, when one logical task is implemented by a combination of higher-order functions, then the time devoted to the task is divided among these functions in a way which disguises the time spent on the task itself. [from section 10.1]
I'd encountered this in Ruby profiling too, but I hadn't really identified it as a problem that needed solving. See, for example, this flat profile (from a Ruby profiler project), where Integer#upto (the rough equivalent of a for loop) is at the top. The more general problem for profilers is that control flow isn't neatly nested in these languages, and this problem is worse with laziness.

In the Haskell world, solutions to problems always involve publishing a paper. Here's the overview from the GHC manual: you can annotate sections of your code with names and the profiler assigns time to those sections.

  • your vcs sucks

    I've been hacking on some Haskell stuff lately that's all managed in darcs and it's reminded me of an observation I made over two years ago now (see…

  • perl people, explain your language to me

    Every time I use perl I feel mildly positive about it right up until I encounter CPAN. I've never managed to make CPAN work, despite the multitude of…

  • dns attack of doom

    If I've learned anything from the new Kaminsky DNS attack, it's that if you want to keep something a secret while disclosing to a trusted subset of…

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.