Aha: 

# Fast, got to declare the object!
function test5{T}(o::Type{T}, n)
summ=0
    for i=1:n
        summ=summ+o(i)
    end
return summ
end

julia> include("fun.jl")
test1(g, n) = 50023457750685
elapsed time: 0.619951473 seconds (480173520 bytes allocated, 27.32% gc 
time)
test2(n) = 50023457750685
elapsed time: 0.002951912 seconds (75304 bytes allocated)
test4(MyFun1(), n) = 50023457750685
elapsed time: 0.003362795 seconds (90436 bytes allocated)
test1(MyFun3, n) = 50023457750685
elapsed time: 0.661085013 seconds (480184232 bytes allocated, 23.39% gc 
time)
test5(MyFun3, n) = 50023457750685
elapsed time: 0.003583276 seconds (116768 bytes allocated)

Reply via email to