-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Multiplying and adding UnitType numbers seems slow. Here's an example (not saying this is what you would necessarily do with unitful numbers but it has a lot of operations so it's easy to benchmark reliably):
julia> a =fill(u"m",(100,100))
100×100 Matrix{Meter}:
julia> b = rand(100,100);
julia> f(c) = c*c
f (generic function with 1 method)
julia> @benchmark f($a)
BenchmarkTools.Trial: 138 samples with 1 evaluation per sample.
Range (min … max): 31.454 ms … 53.650 ms ┊ GC (min … max): 0.00% … 0.00%
Time (median): 35.954 ms ┊ GC (median): 6.07%
Time (mean ± σ): 36.352 ms ± 4.104 ms ┊ GC (mean ± σ): 5.59% ± 4.95%
█ ▆ ▁ ▂
██▆█▆▃▅▄█▄▄▅▄▄▆▇█▆▆▇▃▆▆▅▄▅▄▃▃▅▁▁▃▃▃▃▁▁▁▁▁▁▁▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▃ ▃
31.5 ms Histogram: frequency by time 53.2 ms <
Memory estimate: 31.51 MiB, allocs estimate: 2050003.
julia> @benchmark f($b)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
Range (min … max): 23.300 μs … 7.263 ms ┊ GC (min … max): 0.00% … 98.99%
Time (median): 29.400 μs ┊ GC (median): 0.00%
Time (mean ± σ): 38.380 μs ± 103.936 μs ┊ GC (mean ± σ): 8.41% ± 4.47%
▄█▇▆▁
▂▁▂▄█████▅▄▃▂▂▂▂▂▂▂▁▁▁▁▁▁▁▂▄▅▆▆▅▅▄▄▅▄▃▃▃▃▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
23.3 μs Histogram: frequency by time 63.4 μs <
Memory estimate: 78.20 KiB, allocs estimate: 3.For this 100x100 matrix multiply the UnitType numbers take 1300 times longer than Float64 numbers and allocates 400 times as much.
When I run the same test using DynamicQuatitites.jl I get timing results that are identical to just using a Float64:
julia> @benchmark f($a)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
Range (min … max): 23.100 μs … 11.849 ms ┊ GC (min … max): 0.00% … 99.47%
Time (median): 39.200 μs ┊ GC (median): 0.00%
Time (mean ± σ): 38.860 μs ± 147.260 μs ┊ GC (mean ± σ): 8.90% ± 4.11%
▆█▃ ▁
▂████▇▅▄▃▂▂▁▁▁▁▁▂▂▂▂▂▂▁▁▁▁▁▁▂▃▄▆████▇▆▅▄▃▃▃▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
23.1 μs Histogram: frequency by time 58.2 μs <
Memory estimate: 78.20 KiB, allocs estimate: 3.
julia> typeof(a)
QuantityArray(::Matrix{Float64}, ::Quantity{Float64, Dimensions{FixedRational{Int32, 25200}}})Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels