// File: /workspace/github_cpp_makefile_star2_O1/umatin[P]LogarithmicErrorRegression/./src/helpers/regression_benchmark.h
// Function: void benchmark_regression<&simple_linear_regression_stable(std::vector<double, std::allocator<double>>&)>(std::vector<double, std::allocator<double>>&, std::vector<double, std::allocator<double>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void benchmark_regression(std::vector<double> & data, std::vector<double> & lookups, std::string regression_name, std::string data_name, std::string outfile){
    auto start = std::chrono::high_resolution_clock::now();
    linear_regression lr = f(data);
    auto stop = std::chrono::high_resolution_clock::now();
    long build_time = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start).count();

    std::vector<long> measurements = perform_benchmark(lr, data, lookups, 30);

    double mean = 0;
    double median = measurements[measurements.size()/2];
    for(int i = 0; i < measurements.size(); i++){
        mean += measurements[i];
    }
    mean /= measurements.size();

    mean /= lookups.size();
    median /= lookups.size();

    long log_error = calculate_error<LogNorm, true, false>(data, lr);
    long d_log_error = calculate_error<DiscreteLogNorm, true, false>(data, lr);
    long mse_error = calculate_error<L2Norm, true, false>(data, lr);

    std::ofstream file;
    file.open(outfile, std::ios_base::app);
    file << regression_name << ";" << data_name << ";" << data.size() << ";" << lookups.size() << ";" << mean << ";" << median << ";" << log_error << ";" << d_log_error << ";" << mse_error << ";" << build_time << std::endl;
    file.close();
    
    std::cout << regression_name << " data_name:" << data_name << " data size:" << data.size() << " lookups size:" << lookups.size() << " mean lookup ns:" << mean << " median lookup ns:" << median << " log error:" << log_error << " discrete log error:" << d_log_error << " mse error:" << mse_error << " build time:" << build_time << std::endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %r8, %r13
movq %rcx, 0x28(%rsp)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbp
callq 0x2040
movq %rax, 0x30(%rsp)
movq %rbp, %rdi
callq 0x276c
vmovsd %xmm0, 0x8(%rsp)
vmovsd %xmm1, (%rsp)
callq 0x2040
movq %rax, 0x38(%rsp)
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
vmovsd 0x8(%rsp), %xmm0
vmovsd (%rsp), %xmm1
movq %rbp, %rsi
movq %r12, %rdx
movl $0x1e, %ecx
callq 0x2e89
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
movq %rdx, %rbx
subq %rax, %rbx
sarq $0x3, %rbx
movq %rbx, %rcx
shrq %rcx
cmpq %rax, %rdx
je 0x4fe0
cmpq $0x1, %rbx
movq %rbx, %rdx
adcq $0x0, %rdx
vxorpd %xmm1, %xmm1, %xmm1
xorl %esi, %esi
vcvtsi2sdq (%rax,%rsi,8), %xmm2, %xmm0
vaddsd %xmm0, %xmm1, %xmm1
incq %rsi
cmpq %rsi, %rdx
jne 0x4fcc
jmp 0x4fe4
vxorpd %xmm1, %xmm1, %xmm1
vmovsd %xmm1, 0x10(%rsp)
vcvtsi2sdq (%rax,%rcx,8), %xmm2, %xmm0
vmovsd %xmm0, 0x40(%rsp)
movq 0x8(%r12), %r14
subq (%r12), %r14
movq %rbp, %rdi
vmovsd 0x8(%rsp), %xmm0
vmovsd (%rsp), %xmm1
callq 0x8858
fisttpll 0x58(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %rbp, %rdi
vmovsd 0x8(%rsp), %xmm0
vmovsd (%rsp), %xmm1
callq 0x891f
fisttpll 0x50(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %rbp, %rdi
vmovsd 0x8(%rsp), %xmm0
vmovsd (%rsp), %xmm1
callq 0x89f0
fisttpll 0x48(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x2350
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x20e0
movq (%r15), %rsi
movq 0x8(%r15), %rdx
leaq 0x78(%rsp), %rdi
callq 0x2270
movq %rax, %r13
leaq 0x52c9(%rip), %rsi      # 0xa362
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
movq 0x28(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r13, %rdi
callq 0x2270
movq %rax, %r13
leaq 0x529e(%rip), %rsi      # 0xa362
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x3, %rsi
movq %r13, %rdi
callq 0x2140
movq %rax, %r13
leaq 0x5273(%rip), %rsi      # 0xa362
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
movq 0x8(%r12), %rsi
subq (%r12), %rsi
sarq $0x3, %rsi
movq %r13, %rdi
callq 0x2140
movq %rax, %r13
leaq 0x5247(%rip), %rsi      # 0xa362
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
vcvtusi2sd %rbx, %xmm2, %xmm0
vmovsd 0x10(%rsp), %xmm1
vdivsd %xmm0, %xmm1, %xmm0
sarq $0x3, %r14
vcvtusi2sd %r14, %xmm2, %xmm1
vmovsd %xmm1, (%rsp)
vdivsd %xmm1, %xmm0, %xmm0
movq %r13, %rdi
vmovsd %xmm0, 0x10(%rsp)
callq 0x2310
movq %rax, %r13
leaq 0x51ff(%rip), %rsi      # 0xa362
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
vmovsd 0x40(%rsp), %xmm0
vdivsd (%rsp), %xmm0, %xmm0
movq %r13, %rdi
vmovsd %xmm0, (%rsp)
callq 0x2310
movq %rax, %r13
leaq 0x51d0(%rip), %rsi      # 0xa362
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
movq %r13, %rdi
movq 0x20(%rsp), %rsi
callq 0x2210
movq %rax, %r13
leaq 0x51ac(%rip), %rsi      # 0xa362
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0x2210
movq %rax, %r13
leaq 0x5188(%rip), %rsi      # 0xa362
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
movq %r13, %rdi
movq 0x8(%rsp), %rsi
callq 0x2210
movq %rax, %r13
leaq 0x5164(%rip), %rsi      # 0xa362
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
movq 0x38(%rsp), %rsi
subq 0x30(%rsp), %rsi
movq %r13, %rdi
movq %rsi, %rbx
callq 0x2210
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2230
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
leaq 0x78(%rsp), %rdi
callq 0x22d0
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq 0x8d6e(%rip), %rdi      # 0xdfd0
callq 0x2270
movq %rax, %r15
leaq 0x50f3(%rip), %rsi      # 0xa364
movl $0xb, %edx
movq %rax, %rdi
callq 0x2270
movq 0x28(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r15, %rdi
callq 0x2270
movq %rax, %r14
leaq 0x50d4(%rip), %rsi      # 0xa370
movl $0xb, %edx
movq %rax, %rdi
callq 0x2270
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x3, %rsi
movq %r14, %rdi
callq 0x2140
movq %rax, %r14
leaq 0x50b5(%rip), %rsi      # 0xa37c
movl $0xe, %edx
movq %rax, %rdi
callq 0x2270
movq 0x8(%r12), %rsi
subq (%r12), %rsi
sarq $0x3, %rsi
movq %r14, %rdi
callq 0x2140
movq %rax, %r14
leaq 0x5098(%rip), %rsi      # 0xa38b
movl $0x10, %edx
movq %rax, %rdi
callq 0x2270
movq %r14, %rdi
vmovsd 0x10(%rsp), %xmm0
callq 0x2310
movq %rax, %r14
leaq 0x5084(%rip), %rsi      # 0xa39c
movl $0x12, %edx
movq %rax, %rdi
callq 0x2270
movq %r14, %rdi
vmovsd (%rsp), %xmm0
callq 0x2310
movq %rax, %r14
leaq 0x507c(%rip), %rsi      # 0xa3b8
movl $0xb, %edx
movq %rax, %rdi
callq 0x2270
movq %r14, %rdi
movq 0x20(%rsp), %rsi
callq 0x2210
movq %rax, %r14
leaq 0x504f(%rip), %rsi      # 0xa3af
movl $0x14, %edx
movq %rax, %rdi
callq 0x2270
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x2210
movq %rax, %r14
leaq 0x5040(%rip), %rsi      # 0xa3c4
movl $0xb, %edx
movq %rax, %rdi
callq 0x2270
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x2210
movq %rax, %r14
leaq 0x5028(%rip), %rsi      # 0xa3d0
movl $0xc, %edx
movq %rax, %rdi
callq 0x2270
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2210
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq 0x8bd7(%rip), %rax      # 0xdfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x80(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x78(%rsp,%rcx)
callq 0x21c0
leaq 0x170(%rsp), %rdi
callq 0x20a0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x5436
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5454
fstp %st(0)
jmp 0x5454
fstp %st(0)
jmp 0x5454
fstp %st(0)
movq %rax, %rbx
jmp 0x5466
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x22e0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x547d
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
movq %rbx, %rdi
callq 0x2360