Ok. Well, here is Julia code that’s better:

function divsum(n::Int)
        s = 0
        for x in 1:(n - 1)
                if rem(n, x) == 0
                        s += x
                end
        end
        return s
end

function amicable(n::Int)
        d = divsum(n)
        return d != n && divsum(d) == n
end

function amicablesum(bound::Int)
        s = 0
        for n in 1:bound
                if amicable(n)
                        s += n
                end
        end
        return s
end

function getsum()
        t = @elapsed res = amicablesum(9999)
        return t, res
end

getsum()

On my machine, that produces the tuple, (0.783862268,31626).

 — John

On Mar 16, 2014, at 1:44 PM, Stefan Schwarz <fxbr...@gmail.com> wrote:

> If you refer to the MainEvaluator and rule based approach inside Mathematic 
> plus that there is no real function call semantics...
> no. Performance comparisons must be absolute, despite of a (sometimes) 
> nebulous execution model Mathematica has.
> 
> Are you saying, that if you'd use a similar execution model that Mathematica 
> has you gain more speed?
> You're able to change the execution model of a llvm IR code generator? How 
> you gonna do this?
> 
> I don't think that you can change the code to gain more speed, because you 
> involve a special execution model, 
> but I do believe that you can better Julia code that I've done.

Reply via email to