alpar@368: /* -*- mode: C++; indent-tabs-mode: nil; -*- alpar@368: * alpar@368: * This file is a part of LEMON, a generic C++ optimization library. alpar@368: * alpar@368: * Copyright (C) 2003-2009 alpar@368: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@368: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@368: * alpar@368: * Permission to use, modify and distribute this software is granted alpar@368: * provided that this copyright notice appears in all copies. For alpar@368: * precise terms see the accompanying LICENSE file. alpar@368: * alpar@368: * This software is provided "AS IS" with no warranty of any kind, alpar@368: * express or implied, and with no claim as to its suitability for any alpar@368: * purpose. alpar@368: * alpar@368: */ alpar@368: alpar@368: ///\file alpar@368: ///\brief Some basic non-inline functions and static global data. alpar@368: alpar@368: #include alpar@368: alpar@368: #ifdef WIN32 alpar@368: #ifndef WIN32_LEAN_AND_MEAN alpar@368: #define WIN32_LEAN_AND_MEAN alpar@368: #endif alpar@368: #ifndef NOMINMAX alpar@368: #define NOMINMAX alpar@368: #endif tapolcai@370: #ifdef UNICODE tapolcai@370: #undef UNICODE tapolcai@370: #endif alpar@368: #include tapolcai@370: #ifdef LOCALE_INVARIANT tapolcai@370: #define MY_LOCALE LOCALE_INVARIANT tapolcai@370: #else tapolcai@370: #define MY_LOCALE LOCALE_NEUTRAL tapolcai@370: #endif alpar@368: #else alpar@368: #include alpar@368: #include alpar@368: #include alpar@368: #include alpar@368: #endif alpar@368: alpar@368: #include alpar@368: #include alpar@368: alpar@368: namespace lemon { alpar@368: namespace bits { alpar@368: void getWinProcTimes(double &rtime, alpar@368: double &utime, double &stime, alpar@368: double &cutime, double &cstime) alpar@368: { alpar@368: #ifdef WIN32 alpar@368: static const double ch = 4294967296.0e-7; alpar@368: static const double cl = 1.0e-7; alpar@368: alpar@368: FILETIME system; alpar@368: GetSystemTimeAsFileTime(&system); alpar@368: rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime; alpar@368: alpar@368: FILETIME create, exit, kernel, user; alpar@368: if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) { alpar@368: utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime; alpar@368: stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime; alpar@368: cutime = 0; alpar@368: cstime = 0; alpar@368: } else { alpar@368: rtime = 0; alpar@368: utime = 0; alpar@368: stime = 0; alpar@368: cutime = 0; alpar@368: cstime = 0; alpar@368: } alpar@368: #else alpar@368: timeval tv; alpar@368: gettimeofday(&tv, 0); alpar@368: rtime=tv.tv_sec+double(tv.tv_usec)/1e6; alpar@368: alpar@368: tms ts; alpar@368: double tck=sysconf(_SC_CLK_TCK); alpar@368: times(&ts); alpar@368: utime=ts.tms_utime/tck; alpar@368: stime=ts.tms_stime/tck; alpar@368: cutime=ts.tms_cutime/tck; alpar@368: cstime=ts.tms_cstime/tck; alpar@368: #endif alpar@368: } alpar@368: alpar@368: std::string getWinFormattedDate() alpar@368: { alpar@368: std::ostringstream os; alpar@368: #ifdef WIN32 alpar@368: SYSTEMTIME time; alpar@368: GetSystemTime(&time); tapolcai@370: char buf1[11], buf2[9], buf3[5]; tapolcai@370: if (GetDateFormat(MY_LOCALE, 0, &time, tapolcai@370: ("ddd MMM dd"), buf1, 11) && tapolcai@370: GetTimeFormat(MY_LOCALE, 0, &time, tapolcai@370: ("HH':'mm':'ss"), buf2, 9) && tapolcai@370: GetDateFormat(MY_LOCALE, 0, &time, tapolcai@370: ("yyyy"), buf3, 5)) { alpar@368: os << buf1 << ' ' << buf2 << ' ' << buf3; alpar@368: } alpar@368: else os << "unknown"; alpar@368: #else alpar@368: timeval tv; alpar@368: gettimeofday(&tv, 0); alpar@368: alpar@368: char cbuf[26]; alpar@368: ctime_r(&tv.tv_sec,cbuf); alpar@368: os << cbuf; alpar@368: #endif alpar@368: return os.str(); alpar@368: } alpar@368: alpar@368: int getWinRndSeed() alpar@368: { alpar@368: #ifdef WIN32 alpar@368: FILETIME time; alpar@368: GetSystemTimeAsFileTime(&time); alpar@368: return GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime; alpar@368: #else alpar@368: timeval tv; alpar@368: gettimeofday(&tv, 0); alpar@368: return getpid() + tv.tv_sec + tv.tv_usec; alpar@368: #endif alpar@368: } alpar@368: } alpar@368: }