-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Labels
foldsum, maximum, reduce, foldl, etc.sum, maximum, reduce, foldl, etc.performanceMust go fasterMust go faster
Description
A slack conversation led me to the realization that currently the following two functions have very different speeds.
function f(x, y)
return @inbounds mapreduce(==,+,x, y)
end
function f2(x, y)
total=0
@inbounds for i in 1:length(x)
total += x[i]==y[i]
end
return total
end
x = randn(10240); y = similar(x)
@btime f2(x,y)
1.255 μs (0 allocations: 0 bytes)
@btime f(x,y)
9.207 μs (1 allocation: 10.19 KiB)
This is clearly unfortunate as the mapreduce version is much clearer. Is there any way we can make this case for mapreduce not have O(n) allocation? (or otherwise be faster)
Metadata
Metadata
Assignees
Labels
foldsum, maximum, reduce, foldl, etc.sum, maximum, reduce, foldl, etc.performanceMust go fasterMust go faster