// File: ArashPartow[P]exprtk-extras/exprtk_vector_benchmark.cpp
// Function: double run_expression_benchmark<double>(unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned long const&)
T run_expression_benchmark(const std::size_t  vec_size,
                           const std::string& expr_string,
                           const std::size_t& cost)
{
   typedef exprtk::symbol_table<T> symbol_table_t;
   typedef exprtk::expression<T>   expression_t;
   typedef exprtk::parser<T>       parser_t;

   std::vector<T> v0(vec_size, T(2.1234567890));
   std::vector<T> v1(vec_size, T(3.1234567890));
   std::vector<T> v2(vec_size, T(5.1234567890));

   exprtk::rtl::vecops::package<T> vecops_package;

   symbol_table_t symbol_table;
   symbol_table.add_vector("v0",v0);
   symbol_table.add_vector("v1",v1);
   symbol_table.add_vector("v2",v2);
   symbol_table.add_package(vecops_package);

   expression_t expression;
   expression.register_symbol_table(symbol_table);

   parser_t parser;

   if (!parser.compile(expr_string,expression))
   {
      printf("[load_expression] - Parser Error: %s\tExpression: %s\n",
             parser.error().c_str(),
             expr_string.c_str());

      return std::numeric_limits<T>::quiet_NaN();
   }

   exprtk::timer timer;

   T total = T(0);

   timer.start();

   for (std::size_t r = 0; r < rounds; ++r)
   {
      total += expression.value();
   }

   timer.stop();

   if (T(0) != total)
      printf("Total Time:%10.7f Rate:%11.3fevals/sec Perf: %5.3fGFLOPS Expression: %s\n",
             timer.time(),
             rounds / timer.time(),
             (rounds * vec_size * cost) / (1e+9 * timer.time()),
             expr_string.c_str());
   else
      printf("run_expression_benchmark() - Error running benchmark for expression: %s\n",
             expr_string.c_str());

   return timer.time();
}

// Assembly:
subq $0x1498, %rsp           # imm = 0x1498
movq %rdi, 0x1488(%rsp)
movq %rsi, 0x1480(%rsp)
movq %rdx, 0x1478(%rsp)
movq 0x1488(%rsp), %rax
movq %rax, 0x88(%rsp)
movabsq $0x4000fcd6e9b9cb1b, %rax # imm = 0x4000FCD6E9B9CB1B
movq %rax, 0x1458(%rsp)
leaq 0x1457(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x11d800
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rcx
leaq 0x1460(%rsp), %rdi
leaq 0x1458(%rsp), %rdx
callq 0x11d810
jmp 0x11cfdd
leaq 0x1457(%rsp), %rdi
callq 0x11d890
movq 0x1488(%rsp), %rax
movq %rax, 0x78(%rsp)
movabsq $0x4008fcd6e9b9cb1b, %rax # imm = 0x4008FCD6E9B9CB1B
movq %rax, 0x1420(%rsp)
leaq 0x141f(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x11d800
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rcx
leaq 0x1428(%rsp), %rdi
leaq 0x1420(%rsp), %rdx
callq 0x11d810
jmp 0x11d042
leaq 0x141f(%rsp), %rdi
callq 0x11d890
movq 0x1488(%rsp), %rax
movq %rax, 0x68(%rsp)
movabsq $0x40147e6b74dce58d, %rax # imm = 0x40147E6B74DCE58D
movq %rax, 0x13f8(%rsp)
leaq 0x13f7(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x11d800
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rcx
leaq 0x1400(%rsp), %rdi
leaq 0x13f8(%rsp), %rdx
callq 0x11d810
jmp 0x11d0a1
leaq 0x13f7(%rsp), %rdi
callq 0x11d890
leaq 0xc10(%rsp), %rdi
callq 0x11d8a0
jmp 0x11d0bd
leaq 0xc08(%rsp), %rdi
movl $0x1, %esi
callq 0x11dfa0
jmp 0x11d0d1
leaq 0xbe7(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x1136c0
movq 0x60(%rsp), %rdx
leaq 0x33d439(%rip), %rsi    # 0x45a528
leaq 0xbe8(%rsp), %rdi
callq 0x11c7f0
jmp 0x11d0fe
leaq 0xc08(%rsp), %rdi
leaq 0xbe8(%rsp), %rsi
leaq 0x1460(%rsp), %rdx
callq 0x11dfe0
jmp 0x11d11d
leaq 0xbe8(%rsp), %rdi
callq 0x113808
leaq 0xbe7(%rsp), %rdi
callq 0x1137f0
leaq 0xbbf(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x1136c0
movq 0x58(%rsp), %rdx
leaq 0x33d41e(%rip), %rsi    # 0x45a573
leaq 0xbc0(%rsp), %rdi
callq 0x11c7f0
jmp 0x11d164
leaq 0xc08(%rsp), %rdi
leaq 0xbc0(%rsp), %rsi
leaq 0x1428(%rsp), %rdx
callq 0x11dfe0
jmp 0x11d183
leaq 0xbc0(%rsp), %rdi
callq 0x113808
leaq 0xbbf(%rsp), %rdi
callq 0x1137f0
leaq 0xb97(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x1136c0
movq 0x50(%rsp), %rdx
leaq 0x33d3f2(%rip), %rsi    # 0x45a5ad
leaq 0xb98(%rsp), %rdi
callq 0x11c7f0
jmp 0x11d1ca
leaq 0xc08(%rsp), %rdi
leaq 0xb98(%rsp), %rsi
leaq 0x1400(%rsp), %rdx
callq 0x11dfe0
jmp 0x11d1e9
leaq 0xb98(%rsp), %rdi
callq 0x113808
leaq 0xb97(%rsp), %rdi
callq 0x1137f0
leaq 0xc08(%rsp), %rdi
leaq 0xc10(%rsp), %rsi
callq 0x11e0a0
jmp 0x11d21a
leaq 0xb70(%rsp), %rdi
callq 0x11e0d0
jmp 0x11d229
leaq 0xb70(%rsp), %rdi
leaq 0xc08(%rsp), %rsi
callq 0x11e180
jmp 0x11d240
leaq 0xf8(%rsp), %rdi
movl $0x7f, %esi
callq 0x11e230
jmp 0x11d254
leaq 0x248(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x11e360
jmp 0x11d26b
leaq 0xf8(%rsp), %rdi
callq 0x11eb90
movq 0x1480(%rsp), %rsi
leaq 0x248(%rsp), %rdi
leaq 0xb70(%rsp), %rdx
callq 0x11ec00
movb %al, 0x4f(%rsp)
jmp 0x11d29b
movb 0x4f(%rsp), %al
testb $0x1, %al
jne 0x11d538
jmp 0x11d2a9
leaq 0xd8(%rsp), %rdi
leaq 0x248(%rsp), %rsi
callq 0x11f490
jmp 0x11d2c0
leaq 0xd8(%rsp), %rdi
callq 0x113120
movq %rax, 0x40(%rsp)
movq 0x1480(%rsp), %rdi
callq 0x113120
movq 0x40(%rsp), %rsi
movq %rax, %rdx
leaq 0x33d592(%rip), %rdi    # 0x45a880
xorl %eax, %eax
callq 0x1130b0
jmp 0x11d2f7
leaq 0xd8(%rsp), %rdi
callq 0x113808
callq 0x11f550
movsd %xmm0, 0x1490(%rsp)
movl $0x1, 0xd4(%rsp)
jmp 0x11d72a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
leaq 0x1457(%rsp), %rdi
callq 0x11d890
jmp 0x11d7f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
leaq 0x141f(%rsp), %rdi
callq 0x11d890
jmp 0x11d7e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
leaq 0x13f7(%rsp), %rdi
callq 0x11d890
jmp 0x11d7d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
jmp 0x11d7ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
jmp 0x11d7bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
jmp 0x11d3fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
leaq 0xbe8(%rsp), %rdi
callq 0x113808
leaq 0xbe7(%rsp), %rdi
callq 0x1137f0
jmp 0x11d7b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
jmp 0x11d446
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
leaq 0xbc0(%rsp), %rdi
callq 0x113808
leaq 0xbbf(%rsp), %rdi
callq 0x1137f0
jmp 0x11d7b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
jmp 0x11d48f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
leaq 0xb98(%rsp), %rdi
callq 0x113808
leaq 0xb97(%rsp), %rdi
callq 0x1137f0
jmp 0x11d7b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
jmp 0x11d7b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
jmp 0x11d7a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x11eb90
jmp 0x11d7a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
jmp 0x11d796
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1448(%rsp)
movl %eax, 0x1444(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x113808
jmp 0x11d796
leaq 0xa8(%rsp), %rdi
callq 0x11f560
jmp 0x11d547
movq $0x0, 0xa0(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x11f590
jmp 0x11d562
movq $0x0, 0x98(%rsp)
cmpq $0x7d0, 0x98(%rsp) # imm = 0x7D0
jae 0x11d5bf
leaq 0xb70(%rsp), %rdi
callq 0x11f5b0
movsd %xmm0, 0x38(%rsp)
jmp 0x11d591
movsd 0x38(%rsp), %xmm0
addsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0xa0(%rsp)
movq 0x98(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x98(%rsp)
jmp 0x11d56e
leaq 0xa8(%rsp), %rdi
callq 0x11f5d0
jmp 0x11d5ce
xorps %xmm0, %xmm0
ucomisd 0xa0(%rsp), %xmm0
jne 0x11d5e3
jp 0x11d5e3
jmp 0x11d6db
leaq 0xa8(%rsp), %rdi
callq 0x11f600
movsd %xmm0, 0x30(%rsp)
jmp 0x11d5f8
leaq 0xa8(%rsp), %rdi
callq 0x11f600
movsd %xmm0, 0x28(%rsp)
jmp 0x11d60d
movsd 0x28(%rsp), %xmm1
movsd 0x3379f5(%rip), %xmm0   # 0x455010
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x1488(%rsp), %rax
movq 0x1478(%rsp), %rcx
movq (%rcx), %rcx
imulq %rcx, %rax
imulq $0x7d0, %rax, %rax      # imm = 0x7D0
movq %rax, %xmm0
movaps 0x337a81(%rip), %xmm1   # 0x4550d0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x337a85(%rip), %xmm1   # 0x4550e0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x11f600
movsd %xmm0, 0x20(%rsp)
jmp 0x11d685
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x33796f(%rip), %xmm2   # 0x455008
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x1480(%rsp), %rdi
callq 0x113120
movsd 0x30(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movq %rax, %rsi
leaq 0x33d1e5(%rip), %rdi    # 0x45a8b5
movb $0x3, %al
callq 0x1130b0
jmp 0x11d6d9
jmp 0x11d6fd
movq 0x1480(%rsp), %rdi
callq 0x113120
movq %rax, %rsi
leaq 0x33d20c(%rip), %rdi    # 0x45a8fe
xorl %eax, %eax
callq 0x1130b0
jmp 0x11d6fb
jmp 0x11d6fd
leaq 0xa8(%rsp), %rdi
callq 0x11f600
movsd %xmm0, (%rsp)
jmp 0x11d711
movsd (%rsp), %xmm0
movsd %xmm0, 0x1490(%rsp)
movl $0x1, 0xd4(%rsp)
leaq 0x248(%rsp), %rdi
callq 0x11f650
leaq 0xb70(%rsp), %rdi
callq 0x11f850
leaq 0xc08(%rsp), %rdi
callq 0x11f890
leaq 0xc10(%rsp), %rdi
callq 0x11f910
leaq 0x1400(%rsp), %rdi
callq 0x11fb00
leaq 0x1428(%rsp), %rdi
callq 0x11fb00
leaq 0x1460(%rsp), %rdi
callq 0x11fb00
movsd 0x1490(%rsp), %xmm0
addq $0x1498, %rsp           # imm = 0x1498
retq
leaq 0x248(%rsp), %rdi
callq 0x11f650
leaq 0xb70(%rsp), %rdi
callq 0x11f850
leaq 0xc08(%rsp), %rdi
callq 0x11f890
leaq 0xc10(%rsp), %rdi
callq 0x11f910
leaq 0x1400(%rsp), %rdi
callq 0x11fb00
leaq 0x1428(%rsp), %rdi
callq 0x11fb00
leaq 0x1460(%rsp), %rdi
callq 0x11fb00
movq 0x1448(%rsp), %rdi
callq 0x1134c0
nop