织梦CMS - 轻松建站从此开始!

罗索

Linux下,C语言程序运行时间计算(用于测定哪部分程序运行慢,以

落鹤生 发布于 2012-07-15 00:49 点击:次 
用于测定哪部分程序运行慢,以作性能改善
TAG:

#define DEBUGSORT
#ifdef DEBUGSORT

#include <sys/time.h>
static unsigned long long usec(void){
  struct timeval tv;
  gettimeofday(&tv,NULL);
  return (unsigned long long)tv.tv_sec*1000000+tv.tv_usec;
}
static struct {
  const char *file;
  int line;
  unsigned long long usec;
}LOGTABLE[9000000];
static int LOGCOUNT = 0;
void putlog(const char*, const int);
void putlog(const char* file, const int line){
    if(LOGCOUNT<(sizeof(LOGTABLE)/sizeof(LOGTABLE[0]))){
        LOGTABLE[LOGCOUNT].file =  file;
        LOGTABLE[LOGCOUNT].line =  line;
        LOGTABLE[LOGCOUNT].usec =  usec();
        LOGCOUNT++;
    }
}
void printlog(void);
void printlog(void){
        int i;
        for(i=0; i<LOGCOUNT; i++){
                fprintf(stderr, "%s:%d=%lld\n",
                LOGTABLE[i].file,
                LOGTABLE[i].line,
                LOGTABLE[i].usec);
        }
}

#define LOG putlog(__FILE__,__LINE__)
#define PRINTLOG printlog()
#else /* DEBUGSORT */
#define LOG
#define PRINTLOG
#endif /* DEBUGSORT */

(snowmail)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201207/16156.html]
本文出处:百度博客 作者:snowmail 原文
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
相关文章
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容