StaticTools

Philippe_Maincon1
Wed, 03 Apr 2024 08:45:09 +0000
Performance

Hi,

First: I am very much looking forward to StaticCompiler.jl on Windows, I will be putting it to good use!

I understand it’s early days, but I wanted to try out StaticTools.jl to get a feel for the “static dialect”. The code

using StaticTools, BenchmarkTools,StaticArrays

function foo(v)
    a = StackArray(ntuple(i->v,6), 6)
    return sum(a)
end
function bar(v)
    a = SVector{5,Float64}(v,v,v,v,v)
    return a[1]+a[2]+a[3]+a[4]+a[5]
end

@btime foo(2)
@btime bar(2)

yields

  10.210 ns (1 allocation: 64 bytes)
  0.800 ns (0 allocations: 0 bytes)

and I feel cheated: creating a StackArray allocates? On the heap?

What did I get wrong?

3 posts - 2 participants