Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

time.H

Go to the documentation of this file.
00001 #ifndef  TIME_H
00002 #define TIME_H
00003 
00004 #include "platform.H" /* gives windows.h or the *nix equiv that serves up sys/time.h*/
00005 
00006 #ifdef WIN32
00007 
00008 inline double the_time() 
00009 {
00010    LARGE_INTEGER freq, tick;
00011 
00012    //If the high precision counter is supported, these return true
00013    //and give MUCH better resolution (micro seconds vs. 10s of miliseconds)
00014    if (QueryPerformanceFrequency(&freq) && QueryPerformanceCounter(&tick))
00015    {
00016       //Division of __int64's drops too much precision.
00017       //return double(tick.QuadPart/freq.QuadPart);
00018 
00019       //Premultiplying __int64's before division yields overflows.
00020       //return double(tick.QuadPart*100000/freq.QuadPart)/100000.0;
00021 
00022       //Convert to Intel's 80bit doubles!
00023       long double dtick = long double(tick.QuadPart);
00024       long double dfreq = long double(freq.QuadPart);
00025       return dtick/dfreq;
00026    }
00027    else
00028    {
00029       return double(GetTickCount())/1000.0;
00030    }
00031 }
00032     
00033 inline double the_time_ms() 
00034 {
00035    LARGE_INTEGER freq, tick;
00036 
00037    if (QueryPerformanceFrequency(&freq) && QueryPerformanceCounter(&tick))
00038    {
00039       long double dtick = long double(tick.QuadPart);
00040       long double dfreq = long double(freq.QuadPart);
00041       return dtick/dfreq*1000.0;
00042       //return double(tick.QuadPart*100000/freq.QuadPart)/100.0;
00043       //return double(tick.QuadPart*1000/freq.QuadPart);
00044    }
00045    else
00046    {
00047       return double(GetTickCount());
00048    }
00049 }
00050 
00051 #else
00052 
00053 inline double the_time() 
00054 {
00055     struct timeval ts; struct timezone tz;
00056     gettimeofday(&ts, &tz);
00057     return (double)(ts.tv_sec + ts.tv_usec/1e6);
00058 }
00059 inline double the_time_ms() 
00060 {
00061     struct timeval ts; struct timezone tz;
00062     gettimeofday(&ts, &tz);
00063     return (double)(ts.tv_sec*1e3 + ts.tv_usec/1e3);
00064 }
00065 
00066 #endif
00067 
00068 #endif

Generated on Mon Sep 18 11:39:34 2006 for jot by  doxygen 1.4.4