入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

memsetmemcpy的时间、CPU消耗

创建时间:2011-12-22 投稿人: 浏览次数:3595

内存操作真的很快吗?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; }         

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像