In my use case below, Dates.format
is rather slow when applied to a vector.
I was wondering if there is a better way to broadcast this.
I am well aware, that my custom function uses ‘additional knowledge’ (few unique values) and thus the comparison may not be entirely fair. Still I am surprised about the slow execution of the broadcasted version.
using Dates
export datesformatcustom
function datesformatcustom(col,fmt)
uqv = unique(col)
uqvDate = Dates.format.(uqv,fmt)
dateDict = Dict(uqv .=> uqvDate)
res = map(x->dateDict[x],col)
return res
end
sze = 10_000_000;
sze = 1_000_000;
dts = Date(2000,1,1) .+ Dates.Day.(trunc.(Int,1500 * rand(sze)));
@time Dates.format.(dts,"yyyymm"); #20 seconds for 1 mio rows / 260 seconds for 10 mio rows
@time datesformatcustom(dts,"yyyymm"); #0.3 seconds