m_*********@hotmail.com wrote:
If in a small part of the program, I could
use lets say a
valarray<int> var(size);
or a
int* var = new int[ size];
in both times I have to interate several times through the whole array.
I figured (via profiler) already out that this is a crucial part in my
program.
is there in different implementations
a way that the valarray version can keep up with the pointer version?
Do you mean that iterating vector is slower than iterating in the array in the heap? Do
you iterate in the heap array with the same way that you do in vector?
What are the outputs of this program in your system?
#include <iostream>
#include <vector>
#include <ctime>
int main()
{
using namespace std;
clock_t t1, t2, temp;
const unsigned SIZE= 10000000;
vector<int> vec(SIZE);
int *array= new int[SIZE];
for(temp=t1=clock(); !(t1-temp); t1=clock());
;
for(vector<int>::size_type i=0; i<vec.size(); ++i)
vec[i]= i;
t2=clock();
cout<<"Time consumed in vector's case: "<<t2-t1<<"\n";
for(temp=t1=clock(); !(t1-temp); t1=clock());
;
for(unsigned i=0; i<SIZE; ++i)
array[i]= i;
t2=clock();
cout<<"Time consumed in array's case: "<<t2-t1<<"\n";
delete[] array;
}
--
Ioannis Vranos
http://www23.brinkster.com/noicys