memsetmemcpy的时间、CPU消耗
内存操作真的很快吗?memset、memcpy的性能如何呢?以下结果显示,消耗惊人!
100G内存的memset、memcpy消耗时间分别为:6766ms、17687ms;CPU均为51%. 代码: #include "stdafx.h" #include <windows.h> void TestMemset(char *sData,int nSize) { memset(sData,0,nSize); } void TestMemcpy(char *sData,char *sOldData,int nSize) { memcpy(sData,sOldData,nSize); } int _tmain() { char *sData = new char[64*1024]; char *sOldData = new char[64*1024]; DWORD nDwRun = GetTickCount(); for (int nFor = 0;nFor <50;nFor++) { for(int n = 0; n <32000; n++) { TestMemset(sData,64*1024); } } printf("Time=%u ",GetTickCount() - nDwRun); nDwRun = GetTickCount(); for (int nFor = 0;nFor <50;nFor++) { for(int n = 0; n <32000; n++) { TestMemcpy(sData,sOldData,64*1024); } } printf("Time=%u ",GetTickCount() - nDwRun); int nWait =0; scanf("%d",&nWait); return 0; }声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: 系统性能调优(6)----Java异常处理性能优化
- 下一篇: 性能优化系统学习(一):基础知识