放牧代码和思想
专注自然语言处理、机器学习算法
    This thing called love. Know I would've. Thrown it all away. Wouldn't hesitate.

关于time_t,clock_t ,time(),clock(),CLK_TCK, CLOCKS_PER_SEC 的使用

关于time_t,clock_t ,time(),clock(),CLK_TCK, CLOCKS_PER_SEC 的使用

ISO/IEC     9899:1999     标准中有一个宏:     CLOCKS_PER_SEC  

    <1>     tc2     中的     time.h:没有     CLOCKS_PER_SEC,有一个     CLK_TCK  
                                              #define     CLK_TCK     18.2  
    <2>     gcc     中的     time.h:#define     CLOCKS_PER_SEC     ((clock_t)1000)  
                                              #define     CLK_TCK         CLOCKS_PER_SEC  

time返回从1970年1月1日到现在的秒数,是实际时间;
clock()得到的是毫秒做单位的,time()得到的是秒做单位的。

函数名:       clock    
      功       能:       确定处理器时间    
      用       法:       clock_t       clock(void);    
      程序例:    
   
      #include       <time.h>    
      #include       <stdio.h>    
      #include       <dos.h>    
   
      int       main(void)    
      {    
      clock_t       start,       end;    
      start       =       clock();    
   
      delay(2000); //MS VC 6.0 中可用_sleep() 代替delay,header:stdlib.h/iostream或Sleep()

//,header:windows.h
   
      end       =       clock();    
      printf("The       time       was:       %fn",       (end       –       start)       /       CLK_TCK);    
   
      return       0;    
      }

      函数名:       time      
      功         能:       取一天的时间      
      用         法:       logn       time(long       *tloc);      
      程序例:      
   
      #include        
      #include        
      #include        
   
      int       main(void)      
      {      
            time_t       t;      
   
            t       =       time(NULL);      
            printf("The       number       of       seconds       since       January       1,       1970       is       %ld",t);      
            return       0;      
      }     

知识共享许可协议 知识共享署名-非商业性使用-相同方式共享码农场 » 关于time_t,clock_t ,time(),clock(),CLK_TCK, CLOCKS_PER_SEC 的使用

评论 欢迎留言

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

我的作品

HanLP自然语言处理包《自然语言处理入门》