L1VM 3x1 benchmark

I did write a 3x1 benchmark in Brackets inline assembly (JIT-compiler) and Node.js.

Here are the programs: Node.js:

ind = 2
max = 10000000
num = 0

for (ind = 2; ind <= max; ind++)
{
    num = ind
   // console.log ("number ", num, ": ")

    while (num != 1)
    {
        if (num % 2 == 0)
        {
            num = num / 2
        }
        else
        {
            num = num * 3 + 1;
        }
    }
   // console.log (num)
}

Python (update):

ind = 2

for ind in range(2, 10000001):
    num = ind
    while num != 1:
        if num % 2 == 0:
            num = num / 2
        else:
            num = (num * 3) + 1

Brackets inline assembly (updated to better code):

#include <intr.l1h>
(main func)
    (set int64 1 zero 0)
    (set int64 1 max 10000000Q)
    // (set int64 1 max 20)
    (set int64 1 one 1)
    (set int64 1 num 0)
    (set int64 1 ind 2)
    (set int64 1 f 0)
    (set int64 1 result 0)
    (set string s num_str "number ")
    (set string s colon_str ": ")
    (set string s start_str "start:")
    (set string s space_str " ")
    (set int64 1 jit_label_start 0)
    (set int64 1 jit_label_end 0)
    // JIT-compiler setup
    (:jit_start jit_label_start loadl)
    (:jit_end jit_label_end loadl)
    run_jit_comp (jit_label_start, jit_label_end)
    (optimize-if)
    print_s (start_str)
    print_n
    (for-loop)
    (((ind max <=) f =) f for)
        (ind num =)
        (num :3x1_calc !)
        {ind = (ind + one)}
    (next)
    exit (one)
(funcend)
(3x1_calc func)
    #var ~ 3x1_calc
    (set const-int64 1 one~ 1)
    (set const-int64 1 two~ 2)
    (set const-int64 1 three~ 3)
    (ASM)
    stpopi 1
    // intr0 4, 1, 0, 0
    // intr0 4, 0, 0, 0
    loada zero, 0, 0
    loada one~, 0, 2
    loada two~, 0, 3
    loada three~, 0, 4
    // intr0 4, 1, 0, 0
    // intr0 7, 0, 0, 0
    (ASM_END)
    (:3x1_calc_loop)
    (ASM)
    intr0 254, I0, 0, 0
    :3x1_calc_loop_end jmp
    (ASM_END)
    (:jit_start)
    // (:3x1_calc_loop)
    (ASM)
    bandi 1, 2, 5
    eqi 5, 0, 6
    jmpi 6, :3x1_even
    // odd
    muli 1, 4, 1
    addi 1, 2, 1
    jmp :3x1_endif
    :3x1_even
    divi 1, 3, 1
    :3x1_endif
    // intr0 4, 1, 0, 0
    // intr0 7, 0, 0, 0
    (ASM_END)
    (:jit_end)
    (ASM)
    neqi 1, 2, 6
    :3x1_calc_loop_end
    jmpi 6, :3x1_calc_loop
    // intr0 7, 0, 0, 0
    :3x1_calc_end
    // intr0 4, 1, 0, 0
    // intr0 7, 0, 0, 0
    rts
    (ASM_END)
(funcend)

Here the 3x1 calculation is inside the function 3x1_calc.

Here are the run results: Node.js:

$ time node 3x1
node 3x1  19,02s user 0,02s system 99% cpu 19,083 total

L1VM JIT-compiler:

$ time l1vm 3x1-asm-jit -q
start:
l1vm 3x1-asm-jit -q  35,29s user 0,01s system 99% cpu 35,379 total

Python 3.11:

$ time python 3x1.py
python 3x1.py  313,50s user 0,02s system 99% cpu 5:14,34 total

Here is the 3x1 benchmark.