// File: /workspace/github_c_makefile_star2_O0/codeplea[P]tinyexpr/benchmark.c
// Function: bench
void bench(const char *expr, function1 func) {
    int i, j;
    volatile double d;
    double tmp;
    clock_t start;

    te_variable lk = {"a", &tmp};

    printf("Expression: %s\n", expr);

    printf("native ");
    start = clock();
    d = 0;
    for (j = 0; j < loops; ++j)
        for (i = 0; i < loops; ++i) {
            tmp = i;
            d += func(tmp);
        }
    const int nelapsed = (clock() - start) * 1000 / CLOCKS_PER_SEC;

    /*Million floats per second input.*/
    printf(" %.5g", d);
    if (nelapsed)
        printf("\t%5dms\t%5dmfps\n", nelapsed, loops * loops / nelapsed / 1000);
    else
        printf("\tinf\n");




    printf("interp ");
    te_expr *n = te_compile(expr, &lk, 1, 0);
    start = clock();
    d = 0;
    for (j = 0; j < loops; ++j)
        for (i = 0; i < loops; ++i) {
            tmp = i;
            d += te_eval(n);
        }
    const int eelapsed = (clock() - start) * 1000 / CLOCKS_PER_SEC;
    te_free(n);

    /*Million floats per second input.*/
    printf(" %.5g", d);
    if (eelapsed)
        printf("\t%5dms\t%5dmfps\n", eelapsed, loops * loops / eelapsed / 1000);
    else
        printf("\tinf\n");


    printf("%.2f%% longer\n", (((double)eelapsed / nelapsed) - 1.0) * 100.0);


    printf("\n");
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
leaq 0x2e7b(%rip), %rax      # 0x4060
movq %rax, 0x18(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x0, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x60(%rsp), %rsi
leaq 0x2e51(%rip), %rdi      # 0x4062
movb $0x0, %al
callq 0x1070
leaq 0x2e53(%rip), %rdi      # 0x4072
movb $0x0, %al
callq 0x1070
callq 0x1060
movq %rax, 0x38(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rsp)
movl $0x0, 0x50(%rsp)
cmpl $0x2710, 0x50(%rsp)     # imm = 0x2710
jge 0x12a5
movl $0x0, 0x54(%rsp)
cmpl $0x2710, 0x54(%rsp)     # imm = 0x2710
jge 0x1296
cvtsi2sdl 0x54(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x58(%rsp), %rax
movsd 0x40(%rsp), %xmm0
callq *%rax
movaps %xmm0, %xmm1
movsd 0x48(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x1253
jmp 0x1298
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x1241
callq 0x1060
subq 0x38(%rsp), %rax
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
movl %eax, 0x14(%rsp)
movsd 0x48(%rsp), %xmm0
leaq 0x2da9(%rip), %rdi      # 0x407a
movb $0x1, %al
callq 0x1070
cmpl $0x0, 0x14(%rsp)
je 0x1307
movl 0x14(%rsp), %esi
movl $0x5f5e100, %eax        # imm = 0x5F5E100
cltd
idivl 0x14(%rsp)
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
movl %eax, %edx
leaq 0x2d82(%rip), %rdi      # 0x4080
movb $0x0, %al
callq 0x1070
jmp 0x1315
leaq 0x2d82(%rip), %rdi      # 0x4090
movb $0x0, %al
callq 0x1070
leaq 0x2d7a(%rip), %rdi      # 0x4096
movb $0x0, %al
callq 0x1070
movq 0x60(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x2900
movq %rax, 0x8(%rsp)
callq 0x1060
movq %rax, 0x38(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rsp)
movl $0x0, 0x50(%rsp)
cmpl $0x2710, 0x50(%rsp)     # imm = 0x2710
jge 0x13bc
movl $0x0, 0x54(%rsp)
cmpl $0x2710, 0x54(%rsp)     # imm = 0x2710
jge 0x13ad
cvtsi2sdl 0x54(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x8(%rsp), %rdi
callq 0x1d60
movaps %xmm0, %xmm1
movsd 0x48(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x136d
jmp 0x13af
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x135b
callq 0x1060
subq 0x38(%rsp), %rax
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
movl %eax, 0x4(%rsp)
movq 0x8(%rsp), %rdi
callq 0x1750
movsd 0x48(%rsp), %xmm0
leaq 0x2c88(%rip), %rdi      # 0x407a
movb $0x1, %al
callq 0x1070
cmpl $0x0, 0x4(%rsp)
je 0x1428
movl 0x4(%rsp), %esi
movl $0x5f5e100, %eax        # imm = 0x5F5E100
cltd
idivl 0x4(%rsp)
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
movl %eax, %edx
leaq 0x2c61(%rip), %rdi      # 0x4080
movb $0x0, %al
callq 0x1070
jmp 0x1436
leaq 0x2c61(%rip), %rdi      # 0x4090
movb $0x0, %al
callq 0x1070
cvtsi2sdl 0x4(%rsp), %xmm0
cvtsi2sdl 0x14(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd 0x2bc2(%rip), %xmm1     # 0x4010
subsd %xmm1, %xmm0
movsd 0x2bae(%rip), %xmm1     # 0x4008
mulsd %xmm1, %xmm0
leaq 0x2c39(%rip), %rdi      # 0x409e
movb $0x1, %al
callq 0x1070
leaq 0x2fd1(%rip), %rdi      # 0x4444
movb $0x0, %al
callq 0x1070
addq $0x68, %rsp
retq
nop