File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -26,24 +26,24 @@ julia> unitful = convert(Unitful.Quantity, dyn_uni)
26
26
julia> f (x) = x ^ rand (1 : 10 ) * 0.3 ;
27
27
28
28
julia> @btime f ($ dyn_uni);
29
- 80.449 ns (0 allocations: 0 bytes)
29
+ 41.330 ns (0 allocations: 0 bytes)
30
30
31
31
julia> @btime f ($ unitful);
32
- 29.666 μs (42 allocations: 1.91 KiB)
32
+ 29.542 μs (42 allocations: 1.91 KiB)
33
33
```
34
34
35
35
(Note the μ and n.)
36
36
Here, the DynamicUnits quantity object allows the compiler to build a function that is type stable,
37
37
while the Unitful quantity object, which stores its dimensions in the type, requires type inference at runtime.
38
38
39
39
However, if the dimensions in your function * can* be inferred by the compiler,
40
- then you are better off using Unitful:
40
+ then you can get better speeds with Unitful:
41
41
42
42
``` julia
43
43
julia> g (x) = x ^ 2 * 0.3 ;
44
44
45
45
julia> @btime g ($ dyn_uni);
46
- 56.317 ns (0 allocations: 0 bytes)
46
+ 6.083 ns (0 allocations: 0 bytes)
47
47
48
48
julia> @btime g ($ unitful);
49
49
1.958 ns (0 allocations: 0 bytes)
You can’t perform that action at this time.
0 commit comments