-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
performanceMust go fasterMust go fastersearch & findThe find* family of functionsThe find* family of functions
Description
Prompted by this deprecation warning:
Warning: In the future `findall(A)` will only work on boolean collections. Use `findall(x->x!=0, A)` instead.
I decided to do a (n admittedly worst-case) test: A = rand(10_000, 10_000);
julia> @time u = findall(x->x != 0, A); # this assumes 0 = zero(eltype(A))
8.606016 seconds (65.73 k allocations: 260.716 MiB, 2.96% gc time)
julia> @time v = findall(!iszero, A);
12.464981 seconds (40 allocations: 1.531 GiB, 4.27% gc time)
julia> @time w = findall((!iszero).(A));
1.531174 seconds (23 allocations: 1.502 GiB, 12.50% gc time)
julia> u == v == w
true
Had I taken the recommended approach, I would've run into a pretty bad performance regression. As it stands, the best (time) performing approach is among the worst in memory usage; the recommended approach with the anonymous function is bad in time but best in memory, and the negative function is worst in both.
Metadata
Metadata
Assignees
Labels
performanceMust go fasterMust go fastersearch & findThe find* family of functionsThe find* family of functions