L1VM - benchmark loop

Here is a new benchmark ran by Node.js and L1VM. The program adds double floating point numbers in a loop.

Here is the JavaScript program:

// double-benchm-06.js
console.log ("start...");

ind = 0
max = 600000000
count = 1

countd = 1.0;
xd = 23.0
yd = 42.0

for (ind = 0; ind <= max; ind++)
{
    countd = countd + xd;
    countd = countd + xd;
    countd = countd + xd;
    countd = countd + xd;
    countd = countd + xd;
    countd = countd + xd;
    countd = countd + xd;

    countd = countd + yd;
    countd = countd + yd;
    countd = countd + yd;
    countd = countd + yd;
    countd = countd + yd;
    countd = countd + yd;
    countd = countd + yd;
}

console.log (count);
console.log (countd);

The run:

$ time node double-benchm-06.js
start...
1
273000000456

real	0m31,412s
user	0m31,470s
sys	0m0,304s

Here is the C program:

// double-benchm-06.c
//
// to build:
// clang double-benchm-06.c -o double-benchm-06 -O3
//
#include <stdio.h>
#include <stdlib.h>

int main() {
  long long ind = 0;
  long long max = 600000000;

  double countd = 1.0;
  double xd = 23.0;
  double yd = 42.0;

  for (ind = 0; ind <= max; ind++) {
    countd = countd + xd;
    countd = countd + xd;
    countd = countd + xd;
    countd = countd + xd;
    countd = countd + xd;
    countd = countd + xd;
    countd = countd + xd;

    countd = countd + yd;
    countd = countd + yd;
    countd = countd + yd;
    countd = countd + yd;
    countd = countd + yd;
    countd = countd + yd;
    countd = countd + yd;
  }

  printf("%lf\n", countd);
  exit(0);
}

The run:

$ time ./double-benchm-06
273000000456.000000

real	0m14,101s
user	0m14,031s
sys	0m0,022s

And finally here is the Brackets program with inline assembly to get the most speed out of it:

// double-benchm-jit-06-assemb.l1com
//
//
#include <intr.l1h>
(main func)
    (set int64 1 zero 0)
    (set int64 1 one 1)
    (set int64 1 loop 0)
    (set int64 1 maxloop 600000000Q)
    (set double 1 zerod 0.0)
    (set double 1 countd 1.0)
    (set double 1 xd 23.0)
    (set double 1 yd 42.0)
    (ASM)
    loada zero, 0, 0
    loada one, 0, 1
    loada loop, 0, 2
    loadd countd, 0, 3
    loada maxloop, 0, 4
    loadd xd, 0, 5
    loadd yd, 0, 6
    // load labels
    loadl :jit_start, 7
    loadl :jit_end, 8
    intr0 253, 7, 8, 0
    intr0 254, 0, 0, 0
    jmp :next
    :jit_start
    :loop
    // add xd
    addd 3, 5, 3
    addd 3, 5, 3
    addd 3, 5, 3
    addd 3, 5, 3
    addd 3, 5, 3
    addd 3, 5, 3
    addd 3, 5, 3
    // add yd
    addd 3, 6, 3
    addd 3, 6, 3
    addd 3, 6, 3
    addd 3, 6, 3
    addd 3, 6, 3
    addd 3, 6, 3
    addd 3, 6, 3
    // increase loop
    addi 2, 1, 2
    lseqi 2, 4, 10
    :jit_end
    jmpi 10, :loop
    :next
    intr0 5, 3, 0, 0
    intr0 7, 0, 0, 0
    intr0 255, 0, 0, 0
    (ASM_END)
(funcend)

The run:

$ time l1vm double-benchm-jit-06-assemb -q
TIMER ms: 0.5550000000
1
273000000456.0000000000

real	0m15,401s
user	0m15,339s
sys	0m0,017s

So my L1VM is faster than Node here because we did use inline assembly and the JIT-compiler to speed things up. You can write really fast optimized code! My L1VM has a close speed to the C program.

Here are all results:

C program: 0m14,101s / factor 1
Node.js:   0m31,412s / factor 2.2
L1VM:      0m15,401s / factor 1.09