Performance when dispatching on type

Hm, maybe benchmark artifacts?

using BenchmarkTools, StaticArrays

f(u, v) = u*v'

struct ConcType end

F(::Type{ConcType}, u, v) = f(u, v)
F(::ConcType, u, v) = f(u, v)

@btime f(a, b) setup = (a = SVector(1.0,2.0); b = SVector(1.0,2.0,3.0,4.0))
@btime F(cvar, a, b) setup = (cvar = ConcType(); a = SVector(1.0,2.0); b = SVector(1.0,2.0,3.0,4.0))
@btime F(ctyp, a, b) setup = (ctyp = ConcType; a = SVector(1.0,2.0); b = SVector(1.0,2.0,3.0,4.0))

results in

  1.200 ns (0 allocations: 0 bytes)
  1.200 ns (0 allocations: 0 bytes)
  1.200 ns (0 allocations: 0 bytes)
2 Likes