Reliably preventing let-floating and thunk overwriting?

Simon Marlow marlowsd at gmail.com
Fri Nov 6 04:03:06 EST 2009


On 06/11/2009 05:39, Bryan O'Sullivan wrote:
> The criterion benchmarking package is pretty nice to use in general, but
> it has a property that sticks in my craw: ensuring that pure code
> actually gets evaluated on every iteration through the benchmarking loop
> is awkward and fragile.
>
> My current scheme is to increment an Int on every iteration and pass
> that to the function being benchmarked. I document the need for the
> function to somehow use this Int, lest it be let-floated out to the top
> level, where it will be evaluated just once and our measurements will
> become nonsensical.
>
> I wonder if anyone else has any clever ideas about approaches that might
> be less intrusive in the API.

One reliable way to do this would be to dynamically load the code to be 
tested using the GHC API, and call this between each evaluation:

foreign import ccall "revertCAFs" revertCAFs  :: IO ()

(note revertCAFs only works on CAFs in dynamically-loaded object code, 
not interpreted or statically linked CAFs).

Cheers,
	Simon


More information about the Glasgow-haskell-users mailing list