// File: /workspace/github_cpp_makefile_star2_O2/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, %r12
movq %rcx, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
movq %rsi, %r13
movq %rdi, %rbp
callq 0x2030
movq %rbp, %rdi
movq %rax, 0x38(%rsp)
callq 0x26c7
vmovsd %xmm0, (%rsp)
vmovsd %xmm1, 0x10(%rsp)
callq 0x2030
movq %rax, %rbx
leaq 0x60(%rsp), %r14
pushq $0x1e
popq %rcx
vmovsd (%rsp), %xmm0
vmovsd 0x10(%rsp), %xmm1
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x2bf0
movq (%r14), %rax
movq 0x8(%r14), %r15
vxorpd %xmm0, %xmm0, %xmm0
vmovsd %xmm0, 0x8(%rsp)
subq %rax, %r15
sarq $0x3, %r15
movq %r15, %rcx
shrq %rcx
movq (%rax,%rcx,8), %rcx
movq %rcx, 0x40(%rsp)
xorl %ecx, %ecx
cmpq %rcx, %r15
je 0x4446
vcvtsi2sdq (%rax,%rcx,8), %xmm2, %xmm0
vmovsd 0x8(%rsp), %xmm1
incq %rcx
vaddsd %xmm0, %xmm1, %xmm1
vmovsd %xmm1, 0x8(%rsp)
jmp 0x4426
movq 0x8(%r13), %r14
subq (%r13), %r14
vmovsd (%rsp), %xmm0
vmovsd 0x10(%rsp), %xmm1
movq %rbp, %rdi
callq 0x78f8
fisttpll 0x58(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x20(%rsp)
vmovsd (%rsp), %xmm0
vmovsd 0x10(%rsp), %xmm1
movq %rbp, %rdi
callq 0x7957
fisttpll 0x50(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x18(%rsp)
vmovsd (%rsp), %xmm0
vmovsd 0x10(%rsp), %xmm1
movq %rbp, %rdi
callq 0x79b6
fisttpll 0x48(%rsp)
movq 0x48(%rsp), %rax
movq %rax, (%rsp)
leaq 0x78(%rsp), %rdi
callq 0x2330
leaq 0x78(%rsp), %rdi
pushq $0x1
popq %rdx
movq %r12, %rsi
callq 0x20d0
movq 0x30(%rsp), %rsi
leaq 0x78(%rsp), %rdi
callq 0x21a0
leaq 0x4dce(%rip), %rsi      # 0x92ae
movq %rax, %rdi
callq 0x2200
movq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
leaq 0x4db2(%rip), %rsi      # 0x92ae
movq %rax, %rdi
callq 0x2200
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x2120
leaq 0x4d8f(%rip), %rsi      # 0x92ae
movq %rax, %rdi
callq 0x2200
movq 0x8(%r13), %rsi
subq (%r13), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x2120
leaq 0x4d6c(%rip), %rsi      # 0x92ae
movq %rax, %rdi
callq 0x2200
vmovsd 0x8(%rsp), %xmm1
vcvtsi2sd %r15, %xmm2, %xmm0
sarq $0x3, %r14
vdivsd %xmm0, %xmm1, %xmm0
vcvtusi2sd %r14, %xmm2, %xmm1
vmovsd %xmm1, 0x8(%rsp)
vdivsd %xmm1, %xmm0, %xmm0
movq %rax, %rdi
vmovsd %xmm0, 0x10(%rsp)
callq 0x22e0
leaq 0x4d2c(%rip), %rsi      # 0x92ae
movq %rax, %rdi
callq 0x2200
vcvtsi2sdq 0x40(%rsp), %xmm2, %xmm0
vdivsd 0x8(%rsp), %xmm0, %xmm0
movq %rax, %rdi
vmovsd %xmm0, 0x8(%rsp)
callq 0x22e0
leaq 0x4d02(%rip), %rsi      # 0x92ae
movq %rax, %rdi
callq 0x2200
movq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x21e0
leaq 0x4ce6(%rip), %rsi      # 0x92ae
movq %rax, %rdi
callq 0x2200
movq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x21e0
leaq 0x4cca(%rip), %rsi      # 0x92ae
movq %rax, %rdi
callq 0x2200
movq (%rsp), %rsi
movq %rax, %rdi
callq 0x21e0
leaq 0x4caf(%rip), %rsi      # 0x92ae
movq %rax, %rdi
callq 0x2200
subq 0x38(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %rax, %rdi
callq 0x20e0
leaq 0x78(%rsp), %rdi
callq 0x2290
movq 0x89a0(%rip), %rdi      # 0xcfd0
movq 0x30(%rsp), %rsi
callq 0x21a0
leaq 0x4c6f(%rip), %rsi      # 0x92b0
movq %rax, %rdi
callq 0x2200
movq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
leaq 0x4c5f(%rip), %rsi      # 0x92bc
movq %rax, %rdi
callq 0x2200
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x2120
leaq 0x4c48(%rip), %rsi      # 0x92c8
movq %rax, %rdi
callq 0x2200
movq 0x8(%r13), %rsi
subq (%r13), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x2120
leaq 0x4c34(%rip), %rsi      # 0x92d7
movq %rax, %rdi
callq 0x2200
vmovsd 0x10(%rsp), %xmm0
movq %rax, %rdi
callq 0x22e0
leaq 0x4c28(%rip), %rsi      # 0x92e8
movq %rax, %rdi
callq 0x2200
vmovsd 0x8(%rsp), %xmm0
movq %rax, %rdi
callq 0x22e0
leaq 0x4c27(%rip), %rsi      # 0x9304
movq %rax, %rdi
callq 0x2200
movq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x21e0
leaq 0x4c02(%rip), %rsi      # 0x92fb
movq %rax, %rdi
callq 0x2200
movq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x21e0
leaq 0x4bfb(%rip), %rsi      # 0x9310
movq %rax, %rdi
callq 0x2200
movq (%rsp), %rsi
movq %rax, %rdi
callq 0x21e0
leaq 0x4bec(%rip), %rsi      # 0x931c
movq %rax, %rdi
callq 0x2200
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %rax, %rdi
callq 0x20e0
leaq 0x78(%rsp), %rdi
callq 0x22b0
leaq 0x60(%rsp), %rdi
callq 0x60ca
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x477d
fstp %st(0)
jmp 0x477d
fstp %st(0)
jmp 0x477d
fstp %st(0)
movq %rax, %rbx
jmp 0x478f
leaq 0x78(%rsp), %rdi
movq %rax, %rbx
callq 0x22b0
leaq 0x60(%rsp), %rdi
callq 0x60ca
movq %rbx, %rdi
callq 0x2340