This is not the classical globals problem.

This difference is that our (map)reduce functions does a recursive 
reduction (splits in half until the list is shorter than some threshold), 
and BigInt is much more efficient with small numbers than with big numbers.

function mr_pairwise(f::Callable, op::Callable, A::AbstractArray, i1,n) 
    if n < 128 
        @inbounds v = f(A[i1]) 
        for i = i1+1:i1+n-1 
            @inbounds v = op(v,f(A[i])) 
        end 
        return v 
    else 
    n2 = div(n,2) 
    return op(mr_pairwise(f,op,A, i1,n2), mr_pairwise(f,op,A, i1+n2,n-n2)) 
    end 
end

My statement was definitely wrong in some cases where a recursive algorithm 
has advantages.

Ivar

kl. 11:49:53 UTC+1 lørdag 15. februar 2014 skrev harven følgende:
>
>
>
> Le samedi 15 février 2014 11:30:12 UTC+1, Tim Holy a écrit :
>>
>> You're running into the classic globals problem, see the performance tips 
>> section of the manual.
>>
>>
> I am sorry, I don't understand your remark. There are no global variables 
> in the code I posted previously.
> Also, wrapping the code in a function does not get better performance. 
> Maybe I don't understand what is the classic globals problem? 
>
> julia> 
> function test () ;
> let biglist = [string(i) for i in 1:20000] , result = BigInt(1); 
>        @time for x in biglist ; result = result * BigInt(x) ; end ; result 
> ; end
> end
>
> julia> test (generic function with 1 method)
>
> julia> test()
> elapsed time: 0.396508521 seconds (304614928 bytes allocated)
>
>
> julia> test()
> elapsed time: 0.393320767 seconds (304614928 bytes allocated)
>
>
>

Reply via email to