>From the original version of the code I see this timing after code gen:
julia> @time Ke1(N); elapsed time: 0.251365495 seconds (134400208 bytes allocated, 30.13% gc time) julia> @time Ke2(N); elapsed time: 3.923532621 seconds (996800384 bytes allocated, 13.97% gc time) After making all the globals const, I see this: julia> @time Ke1(N); elapsed time: 0.273683599 seconds (131200208 bytes allocated, 28.52% gc time) julia> @time Ke2(N); elapsed time: 0.026985097 seconds (384 bytes allocated) Type annotations everywhere are neither necessary nor recommended. It is recommended not to use lots of non-constant globals. On Fri, Dec 12, 2014 at 9:36 AM, Tim Holy <tim.h...@gmail.com> wrote: > On Thursday, December 11, 2014 08:10:38 PM Petr Krysl wrote: > > The moral of this story is: If you can't or won't declare every single > > variable, don't do loops. They are likely to be a losing proposition. > > Just to follow up further, this is not at all the right moral to absorb > from > this. A better set of morals is: > - use code_typed or TypeCheck or Lint to diagnose problems > - remember that julia optimizes functions as a unit. Therefore, in a loop > with > a type issue, one "brute force" solution is to create a separate function > just > for running that loop. The types will be known when that function gets > compiled (even if you don't annotate anything with their types), and so > your > type problem should evaporate. > > --Tim > >