With the anonymous function approach, you shouldn't be calling eval at all. As a rule, if you're calling eval at all after the startup phase of your program, you're doing something wrong.
On Fri, May 1, 2015 at 10:46 AM, 'Antoine Messager' via julia-users < julia-users@googlegroups.com> wrote: > I am sorry for insisting, but it seems that even with anonymous function, > the time necessary to create an anonymous function or a normal function > (without the @gensym) is linearly increasing with the quantity of function > created. I have tried the following: > > *for i in 1:1000* > * if(i%100==0)* > * print("$(int(i/10))%")* > * end* > * tic()* > * > mymat=sgenerateAdjMat(Nnodes,int(Nnodes*1.5),int(Nnodes*0.3),2);* > * > > degrates=exp((rand(Distributions.Uniform(-3.0*log(10),2.0*log(10)),Nnodes)));* > * > > basalrates=exp((rand(Distributions.Uniform(-3.0*log(10),2.0*log(10)),Nnodes)));* > * > > lhs,rhs,lhsjac,rhsjac=make_funjac_ode(mymat,Nnodes,degrates,basalrates,probact);* > * myfun=make_anonymous_f(lhs,rhs);* > * time[i]=toq()* > *end* > > > <https://lh3.googleusercontent.com/-tyrafotpY98/VUOQKo4IWNI/AAAAAAAAAB0/sDbwnXDvIik/s1600/Capture%2Bd%E2%80%99e%CC%81cran%2B2015-05-01%2Ba%CC%80%2B15.38.03.png> > It the the same with the normal function. > > I know that the creation of the parameters (rhs,lhs...) always takes the > same amount of time. > Anonymous function: I need to eval the following: > *function code_anonymous_f(lhs::Dict, rhs::Dict)* > * lines = {}* > * for key in keys(lhs)* > * push!(lines, :( $(lhs[key]) = $(rhs[key])) )* > * end* > * quote* > * func = (y, fy) -> begin* > * $(lines...)* > * end* > * end* > *end* > > Normal function @gensym expressed only once: > *@gensym f!* > *function code_f(lhs::Dict, rhs::Dict)* > * lines = {}* > * for key in keys(lhs)* > * push!(lines, :( $(lhs[key]) = $(rhs[key])) )* > * end* > * quote* > * function $f!(y, fy)* > * $(lines...)* > * end* > * end* > *end* > > I would need to create around 1.000.000 systems so I don't know what to > do. After 20.000 tryes, it takes like 17 second instead of 0.01 at the > beginning. I don't understand where it could come from. > > Thank you in advance, > Antoine > > Le lundi 27 avril 2015 15:49:56 UTC+1, Antoine Messager a écrit : > >> Dear all, >> >> I need to create a lot of systems of equation, find some characteristics >> of each system and store the system if of interest. Each system is created >> under the same name. It works fine for the first 1000 systems but after the >> program starts to be too slow. I have tried to use the garbage collector >> each time I create a new system but it did not speed up the code. I don't >> know what to do, I don't understand where it could come from. >> >> Cheers, >> Antoine >> >