basix_doc 0.1
/Users/mourrain/Devel/mmx/basix/src/timer.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : timer.cpp
00004 * DESCRIPTION: timers
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license and comes WITHOUT
00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
00009 * If you don't have this file, write to the Free Software Foundation, Inc.,
00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00011 ******************************************************************************/
00012 
00013 #include <basix/timer.hpp>
00014 
00015 namespace mmx {
00016 
00017 #ifdef BASIX_HAVE_GETTIMEOFDAY
00018 #include <sys/time.h>
00019 #include <sys/resource.h>
00020 #else
00021 #include <sys/timeb.h>
00022 #endif
00023 
00024 nat
00025 mmx_time () {
00026 #ifdef BASIX_HAVE_GETTIMEOFDAY
00027   struct timeval tp;
00028   gettimeofday (&tp, NULL);
00029   return (nat) ((time_t) ((tp.tv_sec * 1000) + (tp.tv_usec / 1000)));
00030 #else
00031   timeb tb;
00032   ftime (&tb);
00033   return (nat) ((time_t) ((tb.time * 1000) + tb.millitm));
00034 #endif
00035 }
00036 
00037 double
00038 mmx_var_time () {
00039 #ifdef BASIX_HAVE_GETTIMEOFDAY
00040   struct timeval tp;
00041   gettimeofday (&tp, NULL);
00042   return (((double) tp.tv_sec) * 1000) + ((double) (tp.tv_usec / 1000));
00043 #else
00044   timeb tb;
00045   ftime (&tb);
00046   return (((double) tb.time) * 1000) + ((double) tb.millitm);
00047 #endif
00048 }
00049   
00050 nat
00051 mmx_user_time () {
00052 #if defined(__MINGW__) || defined(__MINGW32__)
00053   return 0;
00054 #else
00055   struct rusage used;
00056   nat t;
00057   getrusage(RUSAGE_SELF, &used);
00058   t = (nat) ((time_t) ((used.ru_utime.tv_sec * 1000)
00059                      + (used.ru_utime.tv_usec / 1000)));
00060   getrusage(RUSAGE_CHILDREN, &used);
00061   return t +  (nat) ((time_t) ((used.ru_utime.tv_sec * 1000)
00062                              + (used.ru_utime.tv_usec / 1000)));
00063 #endif
00064 }
00065 
00066 } // namespace mmx
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines