Code Search for Developers
 
 
  

time.cxx from Boson at Krugle


Show time.cxx syntax highlighted

/************************************************************************

  Routines for measuring time.

  $Id: time.cxx 7108 2005-12-19 21:10:48Z abmann $

 ************************************************************************/

#include <gfx/gfx.h>

#if defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

// Only Windows NT supports getting proper time usage information.
// In Windows 95, we have to settle for measuring real time.
double get_cpu_time()
{
    FILETIME start, end, kernel, user;

    if( !GetThreadTimes(GetCurrentThread(), &start, &end, &kernel, &user) )
    {
	// We're running under Windows 95 instead of NT.
	// Just get the current time and be done with it.
	SYSTEMTIME now;
	GetSystemTime(&now);
	SystemTimeToFileTime(&now, &user);
    }

    // Convert into something we can do math on
    LARGE_INTEGER i;
    i.LowPart = user.dwLowDateTime;
    i.HighPart = user.dwHighDateTime;

#ifdef __GNUC__

    // The Win32 headers shipped with GCC don't define the QuadPart
    // accessor for the LARGE_INTEGER type.  So we have to build it
    // directly.
    long long quad = i.HighPart;
    quad = (quad << 32) + i.LowPart;
    return (double)quad / 1e7;
#else
    // Convert to seconds and return
    return (double)(i.QuadPart) / 1e7;
#endif
}

#elif defined(HAVE_GETRUSAGE)
#include <sys/time.h>
#include <sys/resource.h>

double get_cpu_time()
{
    struct rusage t;

    getrusage(RUSAGE_SELF, &t);

    return (double)t.ru_utime.tv_sec + (double)t.ru_utime.tv_usec/1000000;
}

#elif defined(HAVE_TIMES)
#include <time.h>
#include <sys/times.h>
#ifndef CLK_TCK
#define CLK_TCK CLOCKS_PER_SEC
#endif

double get_cpu_time()
{
    struct tms t;

    times(&t);

    return (double)(t.tms_utime) / (double)CLK_TCK;
}

#else

#error "No supported timing mechanism available."

#endif




See more files for this project here

Boson

Boson is an OpenGL real-time strategy game. It is designed to run on Unix (Linux) computers, and is built on top of the KDE, Qt and kdegames libraries.

Project homepage: http://sourceforge.net/projects/boson
Programming language(s): C,C++
License: other

  gfx/
    arcball.h
    array.h
    baseball.h
    geom3d.h
    geom4d.h
    gfx.h
    gl.h
    glext.h
    gltools.h
    gui.h
    intvec.h
    mat2.h
    mat3.h
    mat4.h
    mfc.h
    quat.h
    raster.h
    script.h
    symmat3.h
    symmat4.h
    trackball.h
    vec2.h
    vec3.h
    vec4.h
    wintools.h
  CMakeLists.txt
  arcball.cxx
  baseball.cxx
  config-libgfx.h.cmake
  geom3d.cxx
  geom4d.cxx
  gltools.cxx
  gui.cxx
  mat2.cxx
  mat3.cxx
  mat4.cxx
  quat.cxx
  raster-jpeg.cxx
  raster-png.cxx
  raster-pnm.cxx
  raster-tiff.cxx
  raster.cxx
  script.cxx
  symmat3.cxx
  symmat4.cxx
  time.cxx
  trackball.cxx
  wintools.cxx