Consider the following two code fragments, I try to measure the running time of func(dataMatrix, dim)
.
1st code fragment:
auto start_s=chrono::high_resolution_clock::now();
func(dataMatrix, dim);
auto end_s=chrono::high_resolution_clock::now();
double online_Time=(chrono::duration_cast<chrono::nanoseconds>(end_s-start_s).count());
2nd code fragment:
double**PP=new double*[n];
double*A=new double[n];
for(int i=0;i<n;i++)
PP[i]=new double[dim];
delete[] A;
for(int i=0;i<n;i++)
delete[] PP[i];
delete[] PP;
auto start_s=chrono::high_resolution_clock::now();
func(dataMatrix, dim);
auto end_s=chrono::high_resolution_clock::now();
double online_Time=(chrono::duration_cast<chrono::nanoseconds>(end_s-start_s).count());
After I measure the time, I find that the elapsed time of func(dataMatrix, dim)
in 2nd code fragment is significantly (71x) slower than the 1st fragment.
I originally think that the elapsed time should be the same since the first 11 lines of the 2nd code fragment should not affect the elapsed time.
What is/are the reason(s) behind that?
Aucun commentaire:
Enregistrer un commentaire