in my current project i need to operate on large data array. so i do a stupid test to check which one will be better , but while trying below code i found dynamic arrays are much slower than static array why so ? or am i doing something wrong ?
here is code (i remove vector (perform equal to dynamic) and boost array (equal to static) from here)
result : static 8 , dynamic 7493
#include<iostream>
#include<vector>
using namespace std;
using namespace boost;
double arr_time;
double darr_time;
void arrr()
{
int arr[100000];
LARGE_INTEGER start,end;
QueryPerformanceCounter(&start);
for(int i=0 ; i <100000 ; ++i)
{
arr[i] = 10 ;
}
for(int i=0 ; i <100000 ; ++i)
{
int x = arr[i];
}
QueryPerformanceCounter(&end);
arr_time += (end.LowPart - start.LowPart);
}
void darr()
{
int *arr = new int[100000];
LARGE_INTEGER start,end;
QueryPerformanceCounter(&start);
for(int i=0 ; i <100000 ; ++i)
{
arr[i] = 10 ;
}
for(int i=0 ; i <100000 ; ++i)
{
int x = arr[i];
}
QueryPerformanceCounter(&end);
darr_time += (end.LowPart - start.LowPart);
delete[] arr;
}
int main(int argc, char** argv)
{
for(int i= 0 ; i <100 ; ++i)
{
arrr();
darr();
}
cout<<"\n--------------------\n";
cout<<arr_time<<endl;
cout<<darr_time<<endl;
return 0;
}
arr_timeanddarr_timeto0..