Skip to content

Feature suggestion: @ballocs #272

@claforte

Description

@claforte

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions