in v1.6.1, when --math-mode=fast
:
julia> @btime cos($1.2);
217.234 ns (8 allocations: 576 bytes)
julia> @btime sin($1.2);
175.154 ns (6 allocations: 544 bytes)
julia> @btime tan($1.2);
188.837 ns (6 allocations: 544 bytes)
while in normal math mode:
julia> @btime cos($1.2);
47.322 ns (2 allocations: 32 bytes)
julia> @btime sin($1.2);
17.283 ns (0 allocations: 0 bytes)
julia> @btime tan($1.2);
29.544 ns (0 allocations: 0 bytes)
two problems here:
-
cos()
allocates in either math mode, while sin()
and tan()
does not in normal math. Supposed that elementary function like cos()
should not allocate, right?
- “fast” math is much slower? perhaps because of the allocation?
thanks.
Something very strange is going on in your case–I can’t reproduce any of this in Julia 1.6.1 on Linux:
Normal math mode:
julia> @btime cos($1.2)
7.360 ns (0 allocations: 0 bytes)
0.3623577544766736
julia> @btime sin($1.2)
7.587 ns (0 allocations: 0 bytes)
0.9320390859672263
julia> @btime tan($1.2)
11.403 ns (0 allocations: 0 bytes)
2.5721516221263188
--math-mode=fast
julia> @btime cos($1.2)
5.883 ns (0 allocations: 0 bytes)
0.3623577544766736
julia> @btime sin($1.2)
5.632 ns (0 allocations: 0 bytes)
0.9320390859672264
julia> @btime tan($1.2)
8.081 ns (0 allocations: 0 bytes)
2.5721516221263188
What is your platform and how did you install Julia?
2 Likes
Mac. Just downloaded the .dmg
from julialang
and simply installed it.
I know the problem: I have overrided Base.isnan()
.
Taking away my own Base.isnan()
and everything back to normal.
lessons learned: functions in Base
could only be extended, not to be overrided…
thanks.
3 Likes