// File: /workspace/github_c_makefile_star2_O3/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 0x1e79(%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 0x1e55(%rip), %rdi      # 0x3072
movq %r14, %rsi
xorl %eax, %eax
callq 0x1090
leaq 0x1e54(%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 0x1d99(%rip), %xmm0     # 0x3008
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
decl %ebp
jne 0x1249
incl %r12d
cmpl $0x2710, %r12d          # imm = 0x2710
jne 0x1241
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 0x1dc6(%rip), %rdi      # 0x308a
movb $0x1, %al
callq 0x1090
addl %r15d, %ebx
je 0x1301
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 0x1d9a(%rip), %rdi      # 0x3090
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
jmp 0x130d
leaq 0x1dfa(%rip), %rdi      # 0x3102
callq 0x1060
leaq 0x1d8c(%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 0x1faa
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 0x19b1
movsd 0x8(%rsp), %xmm1
addsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
addsd 0x1c8e(%rip), %xmm1     # 0x3008
decl %ebp
jne 0x134e
incl %r13d
cmpl $0x2710, %r13d          # imm = 0x2710
jne 0x1345
callq 0x1080
subq %r15, %rax
imulq %r12
movq %rdx, %r15
movq %rdx, %r12
shrq $0x3f, %r12
shrq $0x7, %r15
movq %r14, %rdi
callq 0x1693
movsd (%rsp), %xmm0
leaq 0x1cd3(%rip), %rdi      # 0x308a
movb $0x1, %al
callq 0x1090
addl %r12d, %r15d
je 0x13f6
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 0x1ca6(%rip), %rdi      # 0x3090
movl %r15d, %esi
xorl %eax, %eax
callq 0x1090
jmp 0x1402
leaq 0x1d05(%rip), %rdi      # 0x3102
callq 0x1060
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
divsd %xmm1, %xmm0
addsd 0x1bf3(%rip), %xmm0     # 0x3010
mulsd 0x1bf3(%rip), %xmm0     # 0x3018
leaq 0x1c7c(%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