现在的位置: 首页 > 综合 > 正文

MEMCPY_TEST

2014年11月03日 ⁄ 综合 ⁄ 共 1080字 ⁄ 字号 评论关闭

测试内存拷贝所花费的时间:

一、放在程序段中

{
 char*  tstmem[256] = {0};
 int   index = 0;
 unsigned int  tm1 = 0, tm2 = 0;
 
 memset(tstmem, 0x0 , 256 );
 for( index = 0; index< 2; index++)
 {
  tstmem[index] = malloc(1024*1024);
  if(tstmem[index] != 0)
  {
   memset(tstmem[index], 0x1, 1024*1024);
  }
 }
 printf("----->> mem free : %dMB <<--------/n",index);

 memset(tstmem[0], 0x8, 1024*1024);
 tm1 = ipanel_porting_time_ms();
 for(index = 0; index< 10000; index++)
 {
  memcpy(tstmem[1],tstmem[0],1024*1024);
 }
 tm2 = ipanel_porting_time_ms();
 printf("----->>1MB mem copy used time : %d <<-------- /n",tm2-tm1);
 //测试结果正常
 while(1);
}

 

 

二、直接编译,运行

#include <stdio.h>
#include <sys/time.h>

#define VOBSUB_PROFILE_TIME_BEGIN() struct timeval tv1, tv2; /
     gettimeofday(&tv1, NULL);

#define VOBSUB_PROFILE_TIME_END() gettimeofday(&tv2,NULL); /
     int t = (tv2.tv_sec * 1000 + tv2.tv_usec/1000) - (tv1.tv_sec * 1000 + tv1.tv_usec/1000); /
     printf("### [%s][%s][%d] => time:%d ###/n", __FILE__, __FUNCTION__, __LINE__, t);

int main()
{
 char *src = (char *)malloc(1024*1024*10);
 char *dst = (char *)malloc(1024*1024*10);

 VOBSUB_PROFILE_TIME_BEGIN();
 memcpy(dst, src, 1024*1024*10);
 VOBSUB_PROFILE_TIME_END();

 return 0;
}

 

 

抱歉!评论已关闭.