// File: 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:
subq $0x498, %rsp            # imm = 0x498
movq %rdx, 0x160(%rsp)
movq %rcx, 0x168(%rsp)
movq %r8, 0x170(%rsp)
movq %rdi, 0x490(%rsp)
movq %rsi, 0x488(%rsp)
movq %rdx, 0x480(%rsp)
movq %rcx, 0x478(%rsp)
movq %r8, 0x470(%rsp)
callq 0x2030
movq %rax, 0x468(%rsp)
movq 0x490(%rsp), %rdi
callq 0x2c40
vmovsd %xmm0, 0x458(%rsp)
vmovsd %xmm1, 0x460(%rsp)
callq 0x2030
movq %rax, 0x450(%rsp)
leaq 0x450(%rsp), %rdi
leaq 0x468(%rsp), %rsi
callq 0x6770
movq %rax, 0x438(%rsp)
leaq 0x438(%rsp), %rdi
callq 0x6740
movq %rax, 0x440(%rsp)
leaq 0x440(%rsp), %rdi
callq 0x67c0
movq %rax, 0x448(%rsp)
movq 0x458(%rsp), %rax
movq %rax, 0x410(%rsp)
movq 0x460(%rsp), %rax
movq %rax, 0x418(%rsp)
movq 0x490(%rsp), %rsi
movq 0x488(%rsp), %rdx
vmovsd 0x410(%rsp), %xmm0
vmovsd 0x418(%rsp), %xmm1
leaq 0x420(%rsp), %rdi
movl $0x1e, %ecx
callq 0x3b50
vpxor %xmm0, %xmm0, %xmm0
vmovsd %xmm0, 0x408(%rsp)
leaq 0x420(%rsp), %rdi
callq 0xbcf0
movq %rax, %rsi
shrq %rsi
leaq 0x420(%rsp), %rdi
callq 0x12610
vcvtsi2sdq (%rax), %xmm0, %xmm0
vmovsd %xmm0, 0x400(%rsp)
movl $0x0, 0x3fc(%rsp)
movslq 0x3fc(%rsp), %rax
movq %rax, 0x158(%rsp)
leaq 0x420(%rsp), %rdi
callq 0xbcf0
movq %rax, %rcx
movq 0x158(%rsp), %rax
cmpq %rcx, %rax
jae 0x771d
movslq 0x3fc(%rsp), %rsi
leaq 0x420(%rsp), %rdi
callq 0x12610
vcvtsi2sdq (%rax), %xmm0, %xmm0
vaddsd 0x408(%rsp), %xmm0, %xmm0
vmovsd %xmm0, 0x408(%rsp)
movl 0x3fc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3fc(%rsp)
jmp 0x76b1
leaq 0x420(%rsp), %rdi
callq 0xbcf0
vcvtusi2sd %rax, %xmm0, %xmm1
vmovsd 0x408(%rsp), %xmm0
vdivsd %xmm1, %xmm0, %xmm0
vmovsd %xmm0, 0x408(%rsp)
movq 0x488(%rsp), %rdi
callq 0x6400
vcvtusi2sd %rax, %xmm0, %xmm1
vmovsd 0x408(%rsp), %xmm0
vdivsd %xmm1, %xmm0, %xmm0
vmovsd %xmm0, 0x408(%rsp)
movq 0x488(%rsp), %rdi
callq 0x6400
vcvtusi2sd %rax, %xmm0, %xmm1
vmovsd 0x400(%rsp), %xmm0
vdivsd %xmm1, %xmm0, %xmm0
vmovsd %xmm0, 0x400(%rsp)
movq 0x490(%rsp), %rdi
vmovdqu 0x458(%rsp), %xmm0
vmovdqa %xmm0, 0x3e0(%rsp)
vmovsd 0x3e0(%rsp), %xmm0
vmovsd 0x3e8(%rsp), %xmm1
callq 0x12630
fstpt 0x14c(%rsp)
jmp 0x77d2
fldt 0x14c(%rsp)
fisttpll 0x188(%rsp)
movq 0x188(%rsp), %rax
movq %rax, 0x3f0(%rsp)
movq 0x490(%rsp), %rdi
vmovdqu 0x458(%rsp), %xmm0
vmovdqa %xmm0, 0x3b0(%rsp)
vmovsd 0x3b0(%rsp), %xmm0
vmovsd 0x3b8(%rsp), %xmm1
callq 0x126d0
fstpt 0x140(%rsp)
jmp 0x782a
fldt 0x140(%rsp)
fisttpll 0x180(%rsp)
movq 0x180(%rsp), %rax
movq %rax, 0x3c8(%rsp)
movq 0x490(%rsp), %rdi
vmovdqu 0x458(%rsp), %xmm0
vmovdqa %xmm0, 0x390(%rsp)
vmovsd 0x390(%rsp), %xmm0
vmovsd 0x398(%rsp), %xmm1
callq 0x12770
fstpt 0x134(%rsp)
jmp 0x7882
fldt 0x134(%rsp)
fisttpll 0x178(%rsp)
movq 0x178(%rsp), %rax
movq %rax, 0x3a8(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x2390
jmp 0x78af
movq 0x170(%rsp), %rsi
leaq 0x190(%rsp), %rdi
movl $0x1, %edx
callq 0x20e0
jmp 0x78cb
movq 0x160(%rsp), %rsi
leaq 0x190(%rsp), %rdi
callq 0x21d0
movq %rax, 0x128(%rsp)
jmp 0x78ea
movq 0x128(%rsp), %rdi
leaq 0xd961(%rip), %rsi      # 0x1525a
callq 0x2210
movq %rax, 0x120(%rsp)
jmp 0x7908
movq 0x168(%rsp), %rsi
movq 0x120(%rsp), %rdi
callq 0x21d0
movq %rax, 0x118(%rsp)
jmp 0x7927
movq 0x118(%rsp), %rdi
leaq 0xd924(%rip), %rsi      # 0x1525a
callq 0x2210
movq %rax, 0x110(%rsp)
jmp 0x7945
movq 0x490(%rsp), %rdi
callq 0x6400
movq 0x110(%rsp), %rdi
movq %rax, %rsi
callq 0x2060
movq %rax, 0x108(%rsp)
jmp 0x796c
movq 0x108(%rsp), %rdi
leaq 0xd8df(%rip), %rsi      # 0x1525a
callq 0x2210
movq %rax, 0x100(%rsp)
jmp 0x798a
movq 0x488(%rsp), %rdi
callq 0x6400
movq 0x100(%rsp), %rdi
movq %rax, %rsi
callq 0x2060
movq %rax, 0xf8(%rsp)
jmp 0x79b1
movq 0xf8(%rsp), %rdi
leaq 0xd89a(%rip), %rsi      # 0x1525a
callq 0x2210
movq %rax, 0xf0(%rsp)
jmp 0x79cf
movq 0xf0(%rsp), %rdi
vmovsd 0x408(%rsp), %xmm0
callq 0x2410
movq %rax, 0xe8(%rsp)
jmp 0x79ef
movq 0xe8(%rsp), %rdi
leaq 0xd85c(%rip), %rsi      # 0x1525a
callq 0x2210
movq %rax, 0xe0(%rsp)
jmp 0x7a0d
movq 0xe0(%rsp), %rdi
vmovsd 0x400(%rsp), %xmm0
callq 0x2410
movq %rax, 0xd8(%rsp)
jmp 0x7a2d
movq 0xd8(%rsp), %rdi
leaq 0xd81e(%rip), %rsi      # 0x1525a
callq 0x2210
movq %rax, 0xd0(%rsp)
jmp 0x7a4b
movq 0xd0(%rsp), %rdi
movq 0x3f0(%rsp), %rsi
callq 0x2400
movq %rax, 0xc8(%rsp)
jmp 0x7a6a
movq 0xc8(%rsp), %rdi
leaq 0xd7e1(%rip), %rsi      # 0x1525a
callq 0x2210
movq %rax, 0xc0(%rsp)
jmp 0x7a88
movq 0xc0(%rsp), %rdi
movq 0x3c8(%rsp), %rsi
callq 0x2400
movq %rax, 0xb8(%rsp)
jmp 0x7aa7
movq 0xb8(%rsp), %rdi
leaq 0xd7a4(%rip), %rsi      # 0x1525a
callq 0x2210
movq %rax, 0xb0(%rsp)
jmp 0x7ac5
movq 0xb0(%rsp), %rdi
movq 0x3a8(%rsp), %rsi
callq 0x2400
movq %rax, 0xa8(%rsp)
jmp 0x7ae4
movq 0xa8(%rsp), %rdi
leaq 0xd767(%rip), %rsi      # 0x1525a
callq 0x2210
movq %rax, 0xa0(%rsp)
jmp 0x7b02
movq 0xa0(%rsp), %rdi
movq 0x448(%rsp), %rsi
callq 0x2400
movq %rax, 0x98(%rsp)
jmp 0x7b21
movq 0x98(%rsp), %rdi
movq 0x13490(%rip), %rsi     # 0x1afc0
callq 0x2240
jmp 0x7b37
leaq 0x190(%rsp), %rdi
callq 0x22f0
jmp 0x7b46
movq 0x160(%rsp), %rsi
movq 0x1347b(%rip), %rdi     # 0x1afd0
callq 0x21d0
movq %rax, 0x90(%rsp)
jmp 0x7b64
movq 0x90(%rsp), %rdi
leaq 0xd6e9(%rip), %rsi      # 0x1525c
callq 0x2210
movq %rax, 0x88(%rsp)
jmp 0x7b82
movq 0x168(%rsp), %rsi
movq 0x88(%rsp), %rdi
callq 0x21d0
movq %rax, 0x80(%rsp)
jmp 0x7ba1
movq 0x80(%rsp), %rdi
leaq 0xd6b8(%rip), %rsi      # 0x15268
callq 0x2210
movq %rax, 0x78(%rsp)
jmp 0x7bbc
movq 0x490(%rsp), %rdi
callq 0x6400
movq 0x78(%rsp), %rdi
movq %rax, %rsi
callq 0x2060
movq %rax, 0x70(%rsp)
jmp 0x7bdd
movq 0x70(%rsp), %rdi
leaq 0xd68b(%rip), %rsi      # 0x15274
callq 0x2210
movq %rax, 0x68(%rsp)
jmp 0x7bf5
movq 0x488(%rsp), %rdi
callq 0x6400
movq 0x68(%rsp), %rdi
movq %rax, %rsi
callq 0x2060
movq %rax, 0x60(%rsp)
jmp 0x7c16
movq 0x60(%rsp), %rdi
leaq 0xd661(%rip), %rsi      # 0x15283
callq 0x2210
movq %rax, 0x58(%rsp)
jmp 0x7c2e
movq 0x58(%rsp), %rdi
vmovsd 0x408(%rsp), %xmm0
callq 0x2410
movq %rax, 0x50(%rsp)
jmp 0x7c48
movq 0x50(%rsp), %rdi
leaq 0xd640(%rip), %rsi      # 0x15294
callq 0x2210
movq %rax, 0x48(%rsp)
jmp 0x7c60
movq 0x48(%rsp), %rdi
vmovsd 0x400(%rsp), %xmm0
callq 0x2410
movq %rax, 0x40(%rsp)
jmp 0x7c7a
movq 0x40(%rsp), %rdi
leaq 0xd62a(%rip), %rsi      # 0x152b0
callq 0x2210
movq %rax, 0x38(%rsp)
jmp 0x7c92
movq 0x38(%rsp), %rdi
movq 0x3f0(%rsp), %rsi
callq 0x2400
movq %rax, 0x30(%rsp)
jmp 0x7cab
movq 0x30(%rsp), %rdi
leaq 0xd5f0(%rip), %rsi      # 0x152a7
callq 0x2210
movq %rax, 0x28(%rsp)
jmp 0x7cc3
movq 0x28(%rsp), %rdi
movq 0x3c8(%rsp), %rsi
callq 0x2400
movq %rax, 0x20(%rsp)
jmp 0x7cdc
movq 0x20(%rsp), %rdi
leaq 0xd5d4(%rip), %rsi      # 0x152bc
callq 0x2210
movq %rax, 0x18(%rsp)
jmp 0x7cf4
movq 0x18(%rsp), %rdi
movq 0x3a8(%rsp), %rsi
callq 0x2400
movq %rax, 0x10(%rsp)
jmp 0x7d0d
movq 0x10(%rsp), %rdi
leaq 0xd5af(%rip), %rsi      # 0x152c8
callq 0x2210
movq %rax, 0x8(%rsp)
jmp 0x7d25
movq 0x8(%rsp), %rdi
movq 0x448(%rsp), %rsi
callq 0x2400
movq %rax, (%rsp)
jmp 0x7d3d
movq (%rsp), %rdi
movq 0x13278(%rip), %rsi     # 0x1afc0
callq 0x2240
jmp 0x7d4f
leaq 0x190(%rsp), %rdi
callq 0x2310
leaq 0x420(%rsp), %rdi
callq 0x68f0
addq $0x498, %rsp            # imm = 0x498
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3d8(%rsp)
movl %eax, 0x3d4(%rsp)
jmp 0x7da8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3d8(%rsp)
movl %eax, 0x3d4(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x2310
leaq 0x420(%rsp), %rdi
callq 0x68f0
movq 0x3d8(%rsp), %rdi
callq 0x23b0
nopw %cs:(%rax,%rax)
nopl (%rax)