#include "stdafx.h"
#include "windows.h"
#include "time.h"
#include <vector>
#include <list>
struct Point
{
int x;
int y;
};
int _tmain(int argc, _TCHAR* argv[])
{
Point p= {0,0};
int count = 1000000;
std::vector< Point > points;
points.resize(count);
LARGE_INTEGER s;
LARGE_INTEGER e,f;
QueryPerformanceCounter(&s);
for ( int cnt = 0; cnt < count; cnt++ )
{
points[cnt] = p;
}
QueryPerformanceCounter(&e);
QueryPerformanceFrequency(&f);
LONGLONG x = e.QuadPart-s.QuadPart;
double d = double(x)/f.QuadPart;
std::cout<<d<<std::endl;
return 0;
}
本文展示了一个使用C++进行的基准测试案例,主要对比了使用std::vector容器时的性能表现。通过记录向量中写入大量数据前后的时间差,并计算实际耗时,可以评估std::vector在特定条件下的效率。
1万+

被折叠的 条评论
为什么被折叠?



