// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x40, %rsp
movq %rsi, %rbx
leaq 0x1e7e(%rip), %rax      # 0x3070
movq %rax, 0x20(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, 0x28(%rsp)
andl $0x0, 0x30(%rsp)
movq %rdi, %r14
andq $0x0, 0x38(%rsp)
leaq 0x1e5c(%rip), %rdi      # 0x3072
xorl %r12d, %r12d
movq %r14, %rsi
xorl %eax, %eax
callq 0x1090
leaq 0x1e58(%rip), %rdi      # 0x3082
xorl %eax, %eax
callq 0x1090
callq 0x1080
movq %rax, %r15
movq %r12, 0x8(%rsp)
cmpl $0x2710, %r12d          # imm = 0x2710
je 0x128a
xorpd %xmm0, %xmm0
movl $0x2710, %ebp           # imm = 0x2710
subl $0x1, %ebp
jb 0x1285
movsd %xmm0, 0x18(%rsp)
movsd %xmm0, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
callq *%rbx
addsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
addsd 0x1d85(%rip), %xmm0     # 0x3008
jmp 0x1250
incl %r12d
jmp 0x123e
callq 0x1080
subq %r15, %rax
movl $0x3e8, %ecx            # imm = 0x3E8
cqto
idivq %rcx
movq %rax, %rbx
movsd 0x8(%rsp), %xmm0
leaq 0x1dde(%rip), %rdi      # 0x308a
movb $0x1, %al
callq 0x1090
testl %ebx, %ebx
je 0x12dc
movl $0x5f5e100, %eax        # imm = 0x5F5E100
xorl %edx, %edx
idivl %ebx
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
leaq 0x1dc1(%rip), %rdi      # 0x3090
movl %ebx, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x1090
jmp 0x12e8
leaq 0x1e1f(%rip), %rdi      # 0x3102
callq 0x1060
leaq 0x1db1(%rip), %rdi      # 0x30a0
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x1090
leaq 0x20(%rsp), %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x1ed6
movq %rax, %r14
callq 0x1080
movq %rax, %r15
movq $0x0, 0x8(%rsp)
cmpl $0x2710, %r12d          # imm = 0x2710
je 0x136b
xorpd %xmm0, %xmm0
movl $0x2710, %ebp           # imm = 0x2710
subl $0x1, %ebp
jb 0x1366
movsd %xmm0, 0x18(%rsp)
movq %r14, %rdi
movsd %xmm0, 0x10(%rsp)
callq 0x18dd
addsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
addsd 0x1ca4(%rip), %xmm0     # 0x3008
jmp 0x1331
incl %r12d
jmp 0x131f
callq 0x1080
subq %r15, %rax
movl $0x3e8, %ecx            # imm = 0x3E8
cqto
idivq %rcx
movq %rax, %r15
movq %r14, %rdi
callq 0x15d4
movsd 0x8(%rsp), %xmm0
leaq 0x1cf5(%rip), %rdi      # 0x308a
movb $0x1, %al
callq 0x1090
testl %r15d, %r15d
je 0x13c8
movl $0x5f5e100, %eax        # imm = 0x5F5E100
xorl %edx, %edx
idivl %r15d
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
leaq 0x1cd6(%rip), %rdi      # 0x3090
movl %r15d, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x1090
jmp 0x13d4
leaq 0x1d33(%rip), %rdi      # 0x3102
callq 0x1060
cvtsi2sd %r15d, %xmm0
cvtsi2sd %ebx, %xmm1
divsd %xmm1, %xmm0
addsd 0x1c27(%rip), %xmm0     # 0x3010
mulsd 0x1c27(%rip), %xmm0     # 0x3018
leaq 0x1cb0(%rip), %rdi      # 0x30a8
movb $0x1, %al
callq 0x1090
pushq $0xa
popq %rdi
callq 0x1040
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq