// File: /workspace/github_c_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x1e69(%rip), %rax      # 0x3070
movq %rax, 0x18(%rsp)
leaq 0x10(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x0, 0x28(%rsp)
xorl %r12d, %r12d
movq %r12, 0x30(%rsp)
leaq 0x1e45(%rip), %rdi      # 0x3072
movq %r14, %rsi
xorl %eax, %eax
callq 0x1090
leaq 0x1e44(%rip), %rdi      # 0x3082
xorl %eax, %eax
callq 0x1090
callq 0x1080
movq %rax, %r15
movq %r12, (%rsp)
xorps %xmm0, %xmm0
movl $0x2710, %ebp           # imm = 0x2710
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
callq *%rbx
addsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x1d89(%rip), %xmm0     # 0x3008
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
decl %ebp
jne 0x1259
incl %r12d
cmpl $0x2710, %r12d          # imm = 0x2710
jne 0x1251
callq 0x1080
subq %r15, %rax
movabsq $0x20c49ba5e353f7cf, %r12 # imm = 0x20C49BA5E353F7CF
imulq %r12
movq %rdx, %rbx
movq %rdx, %r15
shrq $0x3f, %r15
shrq $0x7, %rbx
movsd (%rsp), %xmm0
leaq 0x1db6(%rip), %rdi      # 0x308a
movb $0x1, %al
callq 0x1090
addl %r15d, %ebx
je 0x1311
movl $0x5f5e100, %eax        # imm = 0x5F5E100
xorl %edx, %edx
idivl %ebx
cltq
imulq $0x10624dd3, %rax, %rdx # imm = 0x10624DD3
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x26, %rdx
addl %eax, %edx
leaq 0x1d8a(%rip), %rdi      # 0x3090
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
jmp 0x131d
leaq 0x1dea(%rip), %rdi      # 0x3102
callq 0x1060
leaq 0x1d7c(%rip), %rdi      # 0x30a0
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x1090
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x1fce
movq %rax, %r14
callq 0x1080
movq %rax, %r15
movq $0x0, (%rsp)
xorpd %xmm1, %xmm1
movl $0x2710, %ebp           # imm = 0x2710
movsd %xmm1, 0x8(%rsp)
movsd %xmm1, 0x10(%rsp)
movq %r14, %rdi
callq 0x19d5
movsd 0x8(%rsp), %xmm1
addsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
addsd 0x1c7e(%rip), %xmm1     # 0x3008
decl %ebp
jne 0x135e
incl %r13d
cmpl $0x2710, %r13d          # imm = 0x2710
jne 0x1355
callq 0x1080
subq %r15, %rax
imulq %r12
movq %rdx, %r15
movq %rdx, %r12
shrq $0x3f, %r12
shrq $0x7, %r15
movq %r14, %rdi
callq 0x16a3
movsd (%rsp), %xmm0
leaq 0x1cc3(%rip), %rdi      # 0x308a
movb $0x1, %al
callq 0x1090
addl %r12d, %r15d
je 0x1406
movl $0x5f5e100, %eax        # imm = 0x5F5E100
xorl %edx, %edx
idivl %r15d
cltq
imulq $0x10624dd3, %rax, %rdx # imm = 0x10624DD3
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x26, %rdx
addl %eax, %edx
leaq 0x1c96(%rip), %rdi      # 0x3090
movl %r15d, %esi
xorl %eax, %eax
callq 0x1090
jmp 0x1412
leaq 0x1cf5(%rip), %rdi      # 0x3102
callq 0x1060
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
divsd %xmm1, %xmm0
addsd 0x1be3(%rip), %xmm0     # 0x3010
mulsd 0x1be3(%rip), %xmm0     # 0x3018
leaq 0x1c6c(%rip), %rdi      # 0x30a8
movb $0x1, %al
callq 0x1090
movl $0xa, %edi
callq 0x1040
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq