/[ascend]/branches/adrian/ascend/general/tm_time.c
ViewVC logotype

Diff of /branches/adrian/ascend/general/tm_time.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2929 by adrian, Wed Apr 1 10:57:31 2015 UTC revision 2930 by adrian, Mon Jun 1 11:17:13 2015 UTC
# Line 26  Line 26 
26    
27  static boolean f_first = TRUE;  static boolean f_first = TRUE;
28    
29    /* the code with clock_gettime() cannot be used on windows due to posix compability */
30    #ifdef __WIN32__
31    double tm_cpu_time(void)
32    {
33       static clock_t ref;
34       static double dref;
35       clock_t now;
36       double dnow;
37    
38       if( f_first ) {
39          ref = clock();
40          dref = (double) ref;
41          f_first = FALSE;
42       }
43       now = clock();
44       dnow = (double) now;
45    
46       return((dnow - dref) / CLOCKS_PER_SEC);
47    }
48    #else
49  double tm_cpu_time(void){  double tm_cpu_time(void){
50      static struct timespec ref;      static struct timespec ref;
51      struct timespec now;      struct timespec now;
# Line 37  double tm_cpu_time(void){ Line 57  double tm_cpu_time(void){
57      clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now);      clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now);
58      return (now.tv_sec - ref.tv_sec) + 1e-9*(now.tv_nsec - ref.tv_nsec);      return (now.tv_sec - ref.tv_sec) + 1e-9*(now.tv_nsec - ref.tv_nsec);
59  }  }
60    #endif
61    
62  double tm_reset_cpu_time(void)  double tm_reset_cpu_time(void)
63  {  {

Legend:
Removed from v.2929  
changed lines
  Added in v.2930

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22