Well, you're clearly allocating memory and discarding it since the list comprehension and sort both allocate memory. So that's garbage that the GC has to deal with. The GC means that your function's timing will be erratic and, generally, longer on a second pass than during the first.
-- John On Dec 11, 2014, at 11:54 PM, Sean McBane <[email protected]> wrote: > function getIJValues(A::SparseMatrixCSC) > m,n = size(A) > rowcoords = rowvals(A) > coordinates = [] > for j = 1:n > append!(coordinates, [(rowcoords[i],j) for i in nzrange(A,j)]) > end > return sort(coordinates) > end > > > I've never formally studied any computer science or programming so I don't > have a great grasp on what goes on underneath this, but it seems to me like > the only thing the garbage collector should need to do would be free the > memory taken up by the list comprehension inside the loop at the end of the > loop. And perhaps this could be redone in a more efficient manner, but > inlining it like that seemed most natural. But what's strange is that called > twice in a row, with exactly the same input, it takes twice as long the > second time as the first. > > Otherwise, I certainly wouldn't be surprised if this method is inherently > inefficient, since I only picked up the language yesterday. > > -- Sean
