I'm porting some of my programs (solutions of Project Euler problems, btw)
from Java to Julia, to check claims concerning performance. Don't you
worry, no spoilers, here. But there is a solution where I needed sorting.
As long that's sorting by natural order, that seems to work ok, and the
Julia version is almost (but not quite) as fast as the Java program. But as
soon as I introduce a transformation...
Here are some results illustrating what I mean:
julia> a=rand(1000000)
1000000-element Array{Float64,1}:
⋮
julia> @elapsed sort(a)
0.20693414
julia> @elapsed sort(a,by=identity)
0.210779277
julia> @elapsed sort(a,by=x->x)
2.501326137
julia> f(x)=x
f (generic function with 1 method)
julia> @elapsed sort(a,by=f)
5.012442935
julia> @allocated sort(a)
8000192
julia> @allocated sort(a,by=f)
1623226064
Any thoughts what eats up all that time, and all that memory?