You're running into the classic globals problem, see the performance tips 
section of the manual.

On Saturday, February 15, 2014 3:11:08 AM UTC-6, harven wrote:
>
>
>
> Le lundi 10 février 2014 23:22:47 UTC+1, Ivar Nesje a écrit :
>>
>> Currently it is much faster to write a explicit loop, than to use theese 
>> functions. In the 0.3-prerelease version we have a new function foldl and 
>> foldr to do what you want. See the latest docs 
>> http://docs.julialang.org/en/latest/stdlib/base/#Base.reduce
>
>
> Actually, reduce is notably faster than a loop, at least on my computer 
> and for the task at hand.
>
> julia> let biglist = [string(i) for i in 1:20000] , result = BigInt(1); 
>        @time for x in biglist ; result *= BigInt(x) ; end ; result ; end
> elapsed time: 0.381970432 seconds (304614928 bytes allocated)
>
> julia> let biglist = [string(i) for i in 1:20000], result = BigInt(1); 
>        @time result = mapreduce(BigInt,*, BigInt(1), biglist) ;end
> elapsed time: 0.022510823 seconds (3048200 bytes allocated)
>
> I guess that's because reduce (well, mapreduce) uses some special 
> algorithm when feeded with the operators + and *.
>

Reply via email to