I think you might have that the wrong way round - the first run is slower on both of those benchmarks, and allocates more data. In fact, we expect the first run with @time to be slower, as the function needs to be JIT-compiled. Also, if it's the first time you've used the @time macro, the macro itself needs to be compiled. Only the second and subsequent @time runs of a given function represent the running time of the function itself - this is why it's recommended to ignore the first set of timing results when you are measuring these things.
Scott T On Thursday, 10 September 2015 22:20:04 UTC+1, 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] > <javascript:>> 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 >
