#include <iostream>
#include <ctime>
using namespace std;
#define N 4096
void main(){
int **a = new int*[N];
for(int i = 0; i < N; i++)
a[i] = new int[N];
int **b = new int*[N];
for(i = 0; i < N; ++i)
b[i] = new int[N];
int j;
clock_t begin1 = clock();
for(i = 0; i < N; ++i)
for(j = 0; j < N; ++j)
a[i][j] = 2;
//为了避免new运算符执行时间的影响,先将两个空间分配好
clock_t end1 = clock();
clock_t begin2 = clock();
for(i = 0; i< N; ++i)
for(j = 0; j < N; ++j)
a[j][i] = 2;
clock_t end2 = clock();
cout << end1 - begin1 << endl;
cout << end2 - begin2 << endl;
}
数组分页导致的性能损失验证程序
最新推荐文章于 2013-10-07 10:42:49 发布