Functions

walltime.c File Reference

#include <stdlib.h>
#include "portability.h"
Include dependency graph for walltime.c:

Go to the source code of this file.

Functions

double walltime (void)
double usertime (void)

Function Documentation

double usertime ( void   ) 

Gets user time since last call. Currently this only works if the system has getrusage(). otherwise it's just like walltime().

Returns:
the elapsed user time (in double precision) since the last call

Definition at line 39 of file walltime.c.

{
#ifdef HAVE_GETRUSAGE
  struct rusage ru;
  static long start=0, startu;
  static int first=1;

  if(first) {
    first = 0;
    getrusage(RUSAGE_SELF, &ru);
    start = ru.ru_utime.tv_sec;
    startu = ru.ru_utime.tv_usec;
    return 0.0;
  }

  getrusage(RUSAGE_SELF, &ru);

  return( ((double) (ru.ru_utime.tv_sec - start)) + (ru.ru_utime.tv_usec-startu)/1000000.0 );
#else
  return walltime();
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

double walltime ( void   ) 

Gets wall time since last call.

Returns:
the elapsed time (in double precision) since the last call

Definition at line 16 of file walltime.c.

{
  struct timeval tp;
  static long start=0, startu;
  if (!start)
  {
    gettimeofday(&tp, NULL);
    start = tp.tv_sec;
    startu = tp.tv_usec;
    return(0.0);
  }
  gettimeofday(&tp, NULL);
  return( ((double) (tp.tv_sec - start)) + (tp.tv_usec-startu)/1000000.0 );
}

Here is the caller graph for this function: