BenchmarkTools.jl icon indicating copy to clipboard operation
BenchmarkTools.jl copied to clipboard

Feature suggestion: @ballocs

Open claforte opened this issue 3 years ago • 1 comments

Hi, thanks for making this fantastic module! One of the many reasons I love Julia. :-)

I think it would be great if BenchmarkTools came with a macro to report the number of allocations (not bytes), i.e. like @ballocated, but return alloc(...).

This seems to work... maybe this can be considered for inclusion directly in this module?

macro ballocs(args...)
        return esc(quote
            $BenchmarkTools.allocs($BenchmarkTools.minimum($BenchmarkTools.@benchmark $(args...)))
        end)
    end

I use it in my project ( https://github.com/claforte/RayTracingWeekend.jl )'s tests to keep the number of heap allocations to a minimum.

claforte avatar Dec 19 '21 15:12 claforte

Probably fixed by #292

gdalle avatar Jun 13 '23 14:06 gdalle