牛骨文教育服务平台(让学习变的简单)
博文笔记

memsetmemcpy的时间、CPU消耗

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

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

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。