Listing names and sizes of local variables

Here’s an even better solution: Base.summarysize()! Modifying the MWE from above:

using Random, InteractiveUtils

Random.seed!(123456)

function inside(z)
    y = z./100
    return y
end

function wrapper()
    x = 1_000 .* rand(1_000)
    w = inside(x)
    @show Base.summarysize(x)/1024
    @show Base.summarysize(w)/1024
    return w
end

p = wrapper()
@show varinfo()

which returns

Base.summarysize(x) / 1024 = 7.8515625
Base.summarysize(w) / 1024 = 7.8515625
varinfo() = | name             |        size | summary                       |
|:---------------- | -----------:|:----------------------------- |
| Base             |             | Module                        |
| Core             |             | Module                        |
| InteractiveUtils | 182.987 KiB | Module                        |
| Main             |             | Module                        |
| inside           |     0 bytes | typeof(inside)                |
| p                |   7.852 KiB | 1000-element Array{Float64,1} |
| wrapper          |     0 bytes | typeof(wrapper)               |
2 Likes