That’s kind of the point. Note that the fastdate above is also handcrafted to a particular date format, so I am not sure in what sense this could be considered “misleading”.
This is probably the normal use case, which is why it’s probably best benchmarked in the way Tamas did - you incur the cost of constructing a DateFormat once, but that’s easily swamped by the actual date parsing for larger vectors.
Here’s an example with a million Dates which also demonstrates @lungben’s point:
julia> using Dates, BenchmarkTools
julia> function fastdate(str)
@inbounds Date(parse(Int, str[7:10]), parse(Int, str[1:2]), parse(Int, str[4:5]))
end
fastdate (generic function with 1 method)
julia> x = Dates.format.(rand(Date(2010,1,1):Day(1):Date(2030,1,1), 1_000_000), "mm/dd/yyyy");
julia> @btime fastdate.($x);
287.560 ms (3000002 allocations: 99.18 MiB)
julia> df = DateFormat("mm/dd/yyyy")
dateformat"mm/dd/yyyy"
julia> @btime Date.($x, $df);
138.532 ms (3 allocations: 7.63 MiB)
julia> @btime Date.($x, dateformat"mm/dd/yyy");
137.874 ms (3 allocations: 7.63 MiB)