Skip to content

Instantly share code, notes, and snippets.

@jiawenhao2015
Created September 10, 2019 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiawenhao2015/767b724bdcedb32ebf8465bc0e8ae335 to your computer and use it in GitHub Desktop.
Save jiawenhao2015/767b724bdcedb32ebf8465bc0e8ae335 to your computer and use it in GitHub Desktop.
time cost info
bool TimeStaticMine(int id,const char* type)
{
struct TimeInfo
{
long long accu_num;
long long accu_sec;
long long accu_usec;
struct timeval st;
struct timeval ed;
long long this_time_usec;
char type[64];
};
static TimeInfo info[50];
if(id<0)
{
for(int i=0;i<50;i++)memset(info+i,0,sizeof(TimeInfo));
return true;
}
if(type==NULL)
{
gettimeofday(&info[id].st,NULL);
return true;
}
gettimeofday(&info[id].ed,NULL);
info[id].this_time_usec=((info[id].ed.tv_sec)-(info[id].st.tv_sec))*1000000 +
((info[id].ed.tv_usec)-(info[id].st.tv_usec));
if(info[id].type[0]=='\0') strcpy(info[id].type,type);
bool needPrint=false;
info[id].accu_num++;
info[id].accu_usec+=info[id].this_time_usec;
char typeData[100];
sprintf(typeData,"%d-%s",id,info[id].type);
char tmp[256];
sprintf(tmp,"=========step: %s, this time: %lld ms=========",typeData,info[id].this_time_usec / 1000);
printf("%s\n",tmp);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment