Thanks, Kristoffer! Indeed, the cost of wordcloud is higher as compared with the one of copying the array (that is not a large array). Everything is crystal clear now!
Thank you all for your collaboration! Best, Charles On 11 September 2015 at 09:09, Kristoffer Carlsson <[email protected]> wrote: > You have too short timings for them to say much at all. As you can see you > have large variations in the times even after the first run. It is likely > that myfunc2 and myfunc takes virtually the same time since the cost of > copying the array is insignificant to the work that wordcloud has to do. As > you can see in the allocation part, you only save ~400 bytes allocated out > of a total of 20 000 in the wordcloud function. > > On Thursday, September 10, 2015 at 11:20:04 PM UTC+2, Charles Santana > wrote: >> >> Many thanks, guys! Indeed reshape(a,length(a)) is much faster than doing >> in the simplest way. However, it brings another question: >> >> When I ran the command: >> >> function myfunc1(corpus) >> wc = wordcloud(x = corpus[:]) >> end >> >> function myfunc2(corpus) >> wc = wordcloud(x = reshape(corpus,length(corpus))) >> end >> >> I get the following performance: >> >> @time myfunc1(corpus) >> >> 1st running: 398.202 milliseconds (452 k allocations: 17406 KB) >> 2nd running: 144.181 microseconds (374 allocations: 20832 bytes) >> 3rd running: 99.270 microseconds (374 allocations: 20832 bytes) >> 4th running: 93.860 microseconds (374 allocations: 20832 bytes) >> >> @time myfunc2(corpus) >> >> 1st running: 4.102 milliseconds (2667 allocations: 136 KB) >> 2nd running: 110.182 microseconds (375 allocations: 20464 bytes) >> 3rd running: 130.949 microseconds (375 allocations: 20464 bytes) >> 4th running: 120.142 microseconds (375 allocations: 20464 bytes) >> >> It is clear that it is much faster and occupies much less memory in the >> first running. And actually I only need to run it once. However I am >> curious to know why would myfunc2 be slower than the myfunc1 as the number >> of running increase? >> >> Thanks for everything! >> >> Best, >> >> Charles >> >> On 10 September 2015 at 19:24, Steven G. Johnson <[email protected]> >> wrote: >> >>> >>> >>> On Thursday, September 10, 2015 at 10:39:58 AM UTC-4, Seth wrote: >>>> >>>> would vec() also work for you? It's supposed to be pretty fast. >>>> >>>>> <http://www.imedea.uib-csic.es/~charles> >>>>> >>>> >>> vec(a) is equivalent to reshape(a, length(a)), and is fast because it >>> doesn't make a copy of the data. >>> >> >> >> >> -- >> Um axé! :) >> >> -- >> Charles Novaes de Santana, PhD >> http://www.imedea.uib-csic.es/~charles >> > -- Um axé! :) -- Charles Novaes de Santana, PhD http://www.imedea.uib-csic.es/~charles
