I tested it again with @time test2(dtm'[:,1], dtm'[:,2]) and it took only 0.013seconds. I also checked @time test2(v,w) and it resulted similar time. I changed nothing, it was odd.
On Monday, November 10, 2014 3:28:10 PM UTC+8, Daniel Høegh wrote: > > I have made a minimum test case: > a=rand(10000,2) > function newsum(a) > for i in 1:100 > sum(a[:,1])+sum(a[:,2]) > end > end > function newsum(a1,a2) > for i in 1:100 > sum(a1)+sum(a2) > end > end > @time newsum(a) > @time newsum(a[:,1],a[:,2]) > elapsed time: 0.073095574 seconds (17709844 bytes allocated, 23.23% gc > time) > elapsed time: 0.006946504 seconds (244796 bytes allocated) > > I suggest that a[:,1] is making a copy of the data in the a matrix this is > done in each iteration of the first function, but in the second function > this is done only once when the function is called like: > newsum(a[:,1],a[:,2]). >
