测试环境
- i5-4670
- 8G内存
测试代码如下
const int length = 100 * 1024 * 1024;
char* testme = new char[length];
char* testme2 = new char[length];
memset(testme2, 1, length);
clock_t start = clock();
for (int i = 0; i < 100; i++)
{
memcpy_s(testme, length, testme2, length);
}
clock_t end = clock();
cout << "赋值时间合计" << end - start;
- 100MB大小赋值100次用时1407毫秒,平均每次14毫秒
- 10MB大小赋值100次用时138毫秒,平均每次1.4毫秒
- 100MB大小赋值10次用时178毫秒,平均每次17.8毫秒
可以不严谨的得出结论:
赋值用时和赋值大小成正比,且每10MB耗时1.4毫秒。