-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Labels
performanceMust go fasterMust go fasterpotential benchmarkCould make a good benchmark in BaseBenchmarksCould make a good benchmark in BaseBenchmarks
Description
I have pointed this out in a discussion of my pull-request on DataStructures.jl, and I also submitted a related documentation issue, but maybe it should be a Julia issue too. For the function
function testref1(m)
a = [3.0, 4.0, 5.0]
sm = 0.0
for i = 1 : m
q = Ref(a,1)
sm += q[]
end
end
I get the following timing result:
julia> @time testref.testref1(100000000)
1.012 seconds (100 M allocations: 3052 MB, 16.17% gc time)
Notice the huge memory allocation. The reason is that the object q is allocated on the heap rather than the stack. This behavior suggests that Ref(array,index) should not be used in an inner loop of a high-performance code.
Metadata
Metadata
Assignees
Labels
performanceMust go fasterMust go fasterpotential benchmarkCould make a good benchmark in BaseBenchmarksCould make a good benchmark in BaseBenchmarks