I think your loop might be more performant if you were looping over Uint values rather than Int values.
-- John > On Jun 4, 2014, at 3:44 PM, Magnus Lie Hetland <[email protected]> wrote: > >> On Wednesday, June 4, 2014 11:49:54 PM UTC+2, Ivar Nesje wrote: >> It does not look like jl_array_del_end currently frees any memory >> https://github.com/JuliaLang/julia/blob/0dacb65c0587eab268362c4dece1b2c662bef15e/src/array.c#L616 >> > Ah, OK. > >> I think you could gain something by storing pointers or object ids directly >> in a typed array, and avoid the safety features and garbage collector >> traverses that reduces performance. >> > Well, I would have thought so, too, but somehow it doesn't look that way? For > example, consider the following code (inside a function): > > a = Array(Uint, n) > resize!(a, 0) > for i = 1:n > push!(a, i) > end > > I would have thought it would be faster than if you replace Uint with Any – > but it actually seems to be quite a bit slower, for some reason. Let's add a > simple type (omitting the field type declaration on purpose, to create some > overhead): > > type Entry > val > end > > Now, the following code is a tad slower than pushing ints onto an Any array, > but still faster than pushing them onto an Uint array: > > a = Array(Any, n) > resize!(a, 0) > for i = 1:n > push!(a, Entry(i)) > end > > The reason I used Uint and not Int was that I intended to use object_id(). If > I push the ints directly onto an Int array, things are almost as fast as > pushing onto an Any array, but still not quite as fast, oddly enough. (And > pushing object_id(Entry(i)) isn't all that fast.) > > From my rather informal and unsystematic benchmarking, it actually seems that > using a cell array with push! is rather efficient. (But maybe I'm doing > things wrong…)
