The 512 is really a strange thing here which makes me puzzled. Thank you for your advice on the global issue, I really did not build a solid basis in coding :p.
Yijing 在 2014年12月1日星期一UTC-6下午7时26分45秒,Jameson写道: > > don't run tests in global scope: > http://docs.julialang.org/en/latest/manual/performance-tips/ > > as for the results you are seeing: julia maintains a small cache of boxed > small integers to reduce the cost of frequent boxing/unboxing of small > numbers (as you have shown, this threshold is probably at ±512). since no > other optimizations are applying (because of the global scope issue), you > just see this minor fallback optimization > > On Mon Dec 01 2014 at 8:20:55 PM Yijing Wu <[email protected] > <javascript:>> wrote: > >> Hi all, I found a strange problem about a very simple code in julia and >> hopefully I can get some help from you, here is the code: >> >> >> B=[1:1000] >> >> T=zeros(Int64,1000) >> >> for i=1:1000 >> >> @time T[i]=B[i] >> >> println(T[i]) >> >> end >> >> >> And when I run the code, the @time shows that it require 48 bytes allocation >> when i is larger than or equal to 512, and 0 bytes when smaller. Is this a >> problem that can be improved or I have to accept that it is designed to take >> some allocations when larger than 512? >> >> >> Thanks a lot for your help! >> >>
