Gene Goykhman over at Flaky Goodness has a nice hint on profiling garbage collection but the technique is more generally applicable. Goykhman wanted to know how much time he was spending in garbage collection while exporting his blog. It turns out there’s a really easy way to find that out.
The function benchmark-run
will run its argument and report the total running time, the number of garbage collection calls, and the total time spent in garbage collection. That’s useful information to know for any function, even if all you’re interested in is the total running time.
Goykhman was concerned that garbage collection was taking up a significant amount of time in his export process so he arranged to inhibit it when he was exporting his blog. That worked out well for him but even if it’s not your problem, the benchmark-run
function seems like a useful way of measuring the performance of your functions and perhaps adjusting things to improve performance.