How optimize speed of vector initialization?

  • Thread starter Thread starter Borneq
  • Start date Start date
B

Borneq

Guest
I am using boost/multiprecision/cpp_int.hpp for arbitrary length integers computing.

Now I am testing simplest algorithm for multiplication: wiki/Multiplication_algorithm#Long_multiplication

My algorithm tested with Visual 2019 Release is several times slower than boost algorithm, but when I change vecctor do stack constant arrays is faster than Boost for small numbers. Most time is spent in:

vector<SingleDigit> standard_multiply(const vector<SingleDigit>&a, const vector<SingleDigit>&b)
{
int p = a.size();
int q = b.size();
vector<SingleDigit> product;
product.resize(p + q);

In product.resize or
vector<SingleDigit> product(p+q);
Boost sources is more complicated but faster is allocated number.

Continue reading...
 
Back
Top