Question seems to be basic but I am not sure, but to the point. I have three vectors:
std::vector<int> vect1;
std::vector<int> vect2;
std::vector<int> vect3;
And for example vect1 has 3 members (10, 20 and 30), and vect2 has also 3 members with some other values like 15, 25 and 35. And I would like to push back all values of vect1 into vect3, and then push back all values of vect2 into vect3, so vect3 would have 6 members in order: 10, 20, 30, 15, 25, 35.
I know I can do that with for
loop, but I wonder if I have thousands of members like in audio processing (eg. 44100) and each member would have some complex calculation, wouldn't be more CPU saving if I would make some simple steps? I imagine something like:
vect3 = vect1 + vect2;
or
vect3.push_back ...; // and here in some way all values of vect1
vect3.push_back ...; // and here in some way all values of vect2
Maybe it's stupid, because even if there is some simple function like that, I suppose looping would be going somewhere under the ground in std::vector definition. But I just wonder out of curiosity.
At all I was always wondering about some basics things about loops, how much time is consumed by each single step of some basic loop, for example:
int a=0;
for (int i=1; i<=100; i++)
{
a = i;
}
So I can calculate how much time is consumed by execute whole loop. Is there any way I can check it? And other stupid questions, for example, does it matter for CPU load if I create variables outside (before) the loop, like here:
int a;
int b;
int c;
for (int i=0; i<100; i++)
{
a = i * 2;
b = i * 3;
c = a + b;
}
Or maybe better would be like that:
int c;
for (int i=0; i<100; i++)
{
int a = i * 2;
int b = i * 3;
c = a + b;
}
Where to find answer for such questions?