Unitful.jl without parametrizing types on units?

Using @btime randn(5) .* Dimensions(mass=2/5, length=2) as a benchmark, I see a pretty big improvement going to Int8 instead of Int. It won’t make much difference for scalars, but for vectors, it cuts allocations by 75% and time by 19%.

#before:
julia> @btime randn(500) .* Dimensions(mass=2/5, length=2);
  17.086 μs (1012 allocations: 145.22 KiB)
# after:
julia> @btime randn(500) .* Dimensions(mass=2/5, length=2);
  13.984 μs (1011 allocations: 39.77 KiB)
1 Like