Julia being outperformed (20 times) by node

Viewed 146

So I made a JS file to calculate a list of number below 10 that go through certain properties.

// Config //
const maxNum = 30; //The largest number that can be used (even)
const maxLength = maxNum; // The max length of a group

// Default vars
const res = [];
const even = [];
const odd = [];
for(let i = 1; i < maxNum + 1; i++) 
    i%2==0 ? even.push(i) : odd.push(i);

const addNumber = (curr, max, e) => {
    if(curr.length == max) return res.push(curr);
    for(let num of e ? even : odd) {
        if(curr.includes(num) || curr[curr.length-1] > num) continue;
        addNumber([...curr, num], max, !e);
    }
}

for(let i = 1; i < maxLength + 1; i++)
    addNumber([], i, false);

Then I had saw Julia as a good and 'performing' language for Math, so decided to re-write it there. However after doing a benchmark (using Hyperfine) I got an unexpected result: (Julia: 368ms to 395, Bun [with node just behind it]: 13ms to 125ms)

enter image description here

So I did run some warmed up test, same history, and even increasing the maxNum up to 30 (Get really low behind that). And once more bun and node destroyed Julia. So I just wanted to know if it was my code the issue:

const MaxNumber = 10; # Needs to be even!

const res = Vector{Int16}[];
const even = [n*2 for n in 1:(convert(Int16, MaxNumber/2))];
const odd = [n*2-1 for n in 1:(convert(Int16, MaxNumber/2))];

function addNumber(curr::Vector{Int16}, max::Number, toDoEven::Bool)
    if (length(curr) === max)
        return push!(res, curr);
    end
    for num::Int16 in (toDoEven ? even : odd)
        if(!isempty(curr) && (num in curr || last(curr) > num))
            continue;
        end
        addNumber(vcat(curr, num), max, !toDoEven);
    end
end

for i in 1:MaxNumber
    addNumber(Int16[], i, false)
end

(The test were done with the Int8 instead of Int16, changed it to support the 30 MaxNumber length)

So, is it un-optimized code or something I am doing wrong, or is node and bun (while being compiled) defeating Julia (JIT)

0 Answers
Related