File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -39,13 +39,13 @@ julia> unitful = convert(Unitful.Quantity, dyn_uni)
39
39
julia> f (x, i) = x ^ i * 0.3 ;
40
40
41
41
julia> @btime f ($ dyn_uni, 1 );
42
- 8.759 ns (0 allocations: 0 bytes)
42
+ 2.750 ns (0 allocations: 0 bytes)
43
43
44
44
julia> @btime f ($ unitful, 1 );
45
- 30.083 μs (42 allocations: 1.91 KiB)
45
+ 2.718 μs (30 allocations: 1.34 KiB)
46
46
```
47
47
48
- ** ( Note the μ and n.) **
48
+ ** Note the μ and n: this is a 1000x speedup! **
49
49
Here, the DynamicQuantities quantity object allows the compiler to build a function that is type stable,
50
50
while the Unitful quantity object, which stores its dimensions in the type, requires type inference at runtime.
51
51
@@ -56,10 +56,10 @@ then you can get better speeds with Unitful:
56
56
julia> g (x) = x ^ 2 * 0.3 ;
57
57
58
58
julia> @btime g ($ dyn_uni);
59
- 10.051 ns (0 allocations: 0 bytes)
59
+ 1.875 ns (0 allocations: 0 bytes)
60
60
61
61
julia> @btime g ($ unitful);
62
- 2.000 ns (0 allocations: 0 bytes)
62
+ 1.500 ns (0 allocations: 0 bytes)
63
63
```
64
64
65
65
While both of these are type stable,
You can’t perform that action at this time.
0 commit comments