Why is the same code slower in lua than in julia?

Viewed 759

When I write out the same code for finding the smallest possible multiple of a number, Julia is much faster than Lua, both taking ~3 seconds & ~23 seconds respectively.

Here is my Julia code:

function smallest_multiple(x)
    n = 1
    while true
        for i = 1:x
            if n % i != 0
                break
            elseif i == x
                return n
            end
        end
        n += 1
    end
end

println(smallest_multiple(20))

And here is the Lua code:

function Smallest_Multiple(x)
    local n = 1
    while true do
        for i = 1,x do
            if n % i ~= 0 then
                break
            elseif i == x then
                return n
            end
        end
        n = n + 1
    end
end

Is there just a fundamental low-level difference between the languages or an oversight in the code?

0 Answers
Related