// File: /workspace/github_cpp_makefile_star2_O3/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 %rbp, %rdi
movq %rax, 0x30(%rsp)
callq 0x276b
vmovsd %xmm0, 0x8(%rsp)
vmovsd %xmm1, (%rsp)
callq 0x2040
vmovsd 0x8(%rsp), %xmm0
vmovsd (%rsp), %xmm1
leaq 0x60(%rsp), %rbx
movl $0x1e, %ecx
movq %rax, 0x38(%rsp)
movq %rbp, %rsi
movq %r12, %rdx
movq %rbx, %rdi
callq 0x2e23
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 0x4f90
cmpq $0x1, %rbx
movq %rbx, %rdx
vxorpd %xmm1, %xmm1, %xmm1
adcq $0x0, %rdx
xorl %esi, %esi
vcvtsi2sdq (%rax,%rsi,8), %xmm2, %xmm0
incq %rsi
vaddsd %xmm0, %xmm1, %xmm1
cmpq %rsi, %rdx
jne 0x4f7c
jmp 0x4f94
vxorpd %xmm1, %xmm1, %xmm1
vcvtsi2sdq (%rax,%rcx,8), %xmm2, %xmm0
movq 0x8(%r12), %r14
vmovsd %xmm1, 0x10(%rsp)
subq (%r12), %r14
vmovsd %xmm0, 0x40(%rsp)
vmovsd 0x8(%rsp), %xmm0
vmovsd (%rsp), %xmm1
movq %rbp, %rdi
callq 0x87ec
fisttpll 0x58(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x20(%rsp)
vmovsd 0x8(%rsp), %xmm0
vmovsd (%rsp), %xmm1
movq %rbp, %rdi
callq 0x88b3
fisttpll 0x50(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x18(%rsp)
vmovsd 0x8(%rsp), %xmm0
vmovsd (%rsp), %xmm1
movq %rbp, %rdi
callq 0x8984
fisttpll 0x48(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x2350
leaq 0x78(%rsp), %rdi
movl $0x1, %edx
movq %r13, %rsi
callq 0x20e0
movq 0x8(%r15), %rdx
movq (%r15), %rsi
leaq 0x78(%rsp), %rdi
callq 0x2270
leaq 0x52dc(%rip), %rsi      # 0xa322
movl $0x1, %edx
movq %rax, %rdi
movq %rax, %r13
callq 0x2270
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdx
movq (%rax), %rsi
movq %r13, %rdi
callq 0x2270
leaq 0x52b1(%rip), %rsi      # 0xa322
movl $0x1, %edx
movq %rax, %rdi
movq %rax, %r13
callq 0x2270
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x3, %rsi
movq %r13, %rdi
callq 0x2140
leaq 0x5286(%rip), %rsi      # 0xa322
movl $0x1, %edx
movq %rax, %rdi
movq %rax, %r13
callq 0x2270
movq 0x8(%r12), %rsi
subq (%r12), %rsi
sarq $0x3, %rsi
movq %r13, %rdi
callq 0x2140
leaq 0x525a(%rip), %rsi      # 0xa322
movl $0x1, %edx
movq %rax, %rdi
movq %rax, %r13
callq 0x2270
vmovsd 0x10(%rsp), %xmm1
vcvtsi2sd %rbx, %xmm2, %xmm0
sarq $0x3, %r14
vdivsd %xmm0, %xmm1, %xmm0
vcvtusi2sd %r14, %xmm2, %xmm1
vmovsd %xmm1, (%rsp)
vdivsd %xmm1, %xmm0, %xmm0
movq %r13, %rdi
vmovsd %xmm0, 0x10(%rsp)
callq 0x2310
leaq 0x5213(%rip), %rsi      # 0xa322
movl $0x1, %edx
movq %rax, %rdi
movq %rax, %r13
callq 0x2270
vmovsd 0x40(%rsp), %xmm0
vdivsd (%rsp), %xmm0, %xmm0
movq %r13, %rdi
vmovsd %xmm0, (%rsp)
callq 0x2310
leaq 0x51e4(%rip), %rsi      # 0xa322
movl $0x1, %edx
movq %rax, %rdi
movq %rax, %r13
callq 0x2270
movq 0x20(%rsp), %rsi
movq %r13, %rdi
callq 0x2210
leaq 0x51c0(%rip), %rsi      # 0xa322
movl $0x1, %edx
movq %rax, %rdi
movq %rax, %r13
callq 0x2270
movq 0x18(%rsp), %rsi
movq %r13, %rdi
callq 0x2210
leaq 0x519c(%rip), %rsi      # 0xa322
movl $0x1, %edx
movq %rax, %rdi
movq %rax, %r13
callq 0x2270
movq 0x8(%rsp), %rsi
movq %r13, %rdi
callq 0x2210
leaq 0x5178(%rip), %rsi      # 0xa322
movl $0x1, %edx
movq %rax, %rdi
movq %rax, %r13
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 0x8(%r15), %rdx
movq (%r15), %rsi
movq 0x7dbf(%rip), %rdi      # 0xcfd0
callq 0x2270
leaq 0x5107(%rip), %rsi      # 0xa324
movl $0xb, %edx
movq %rax, %rdi
movq %rax, %r15
callq 0x2270
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdx
movq (%rax), %rsi
movq %r15, %rdi
callq 0x2270
leaq 0x50e8(%rip), %rsi      # 0xa330
movl $0xb, %edx
movq %rax, %rdi
movq %rax, %r14
callq 0x2270
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x3, %rsi
movq %r14, %rdi
callq 0x2140
leaq 0x50c9(%rip), %rsi      # 0xa33c
movl $0xe, %edx
movq %rax, %rdi
movq %rax, %r14
callq 0x2270
movq 0x8(%r12), %rsi
subq (%r12), %rsi
sarq $0x3, %rsi
movq %r14, %rdi
callq 0x2140
leaq 0x50ac(%rip), %rsi      # 0xa34b
movl $0x10, %edx
movq %rax, %rdi
movq %rax, %r14
callq 0x2270
vmovsd 0x10(%rsp), %xmm0
movq %r14, %rdi
callq 0x2310
leaq 0x5098(%rip), %rsi      # 0xa35c
movl $0x12, %edx
movq %rax, %rdi
movq %rax, %r14
callq 0x2270
vmovsd (%rsp), %xmm0
movq %r14, %rdi
callq 0x2310
leaq 0x5090(%rip), %rsi      # 0xa378
movl $0xb, %edx
movq %rax, %rdi
movq %rax, %r14
callq 0x2270
movq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x2210
leaq 0x5063(%rip), %rsi      # 0xa36f
movl $0x14, %edx
movq %rax, %rdi
movq %rax, %r14
callq 0x2270
movq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x2210
leaq 0x5054(%rip), %rsi      # 0xa384
movl $0xb, %edx
movq %rax, %rdi
movq %rax, %r14
callq 0x2270
movq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x2210
leaq 0x503c(%rip), %rsi      # 0xa390
movl $0xc, %edx
movq %rax, %rdi
movq %rax, %r14
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 0x7c28(%rip), %rax      # 0xcfc8
leaq 0x80(%rsp), %rdi
movq (%rax), %rcx
movq 0x18(%rax), %rax
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 0x53e5
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 0x5403
fstp %st(0)
jmp 0x5403
fstp %st(0)
jmp 0x5403
fstp %st(0)
movq %rax, %rbx
jmp 0x5415
leaq 0x78(%rsp), %rdi
movq %rax, %rbx
callq 0x22e0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x542c
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
movq %rbx, %rdi
callq 0x2360