ColPack
|
00001 /************************************************************************************ 00002 Copyright (C) 2005-2008 Assefaw H. Gebremedhin, Arijit Tarafdar, Duc Nguyen, 00003 Alex Pothen 00004 00005 This file is part of ColPack. 00006 00007 ColPack is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published 00009 by the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 ColPack is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with ColPack. If not, see <http://www.gnu.org/licenses/>. 00019 ************************************************************************************/ 00020 00021 //using namespace std; 00022 00023 #include "Definitions.h" 00024 00025 #include "Timer.h" 00026 00027 namespace ColPack 00028 { 00029 //Public Constructor 4351 00030 Timer::Timer() 00031 { 00032 00033 } 00034 00035 00036 //Public Destructor 4352 00037 Timer::~Timer() 00038 { 00039 00040 } 00041 00042 00043 //Public Function 4354 00044 void Timer::Start() 00045 { 00046 00047 #ifdef SYSTEM_TIME 00048 00049 ct_BeginTimer = times(&tms_BeginTimer); 00050 00051 #else 00052 00053 ct_BeginTimer = clock(); 00054 00055 #endif 00056 00057 } 00058 00059 //Public Function 4355 00060 void Timer::Stop() 00061 { 00062 00063 #ifdef SYSTEM_TIME 00064 00065 ct_EndTimer = times(&tms_EndTimer); 00066 00067 #else 00068 00069 ct_EndTimer = clock(); 00070 00071 #endif 00072 00073 } 00074 00075 //Public Function 4356 00076 double Timer::GetWallTime() 00077 { 00078 00079 #ifdef SYSTEM_TIME 00080 00081 return (double)(ct_EndTimer - ct_BeginTimer) / CLK_TCK; 00082 00083 #else 00084 00085 return (double)(ct_EndTimer - ct_BeginTimer) / CLOCKS_PER_SEC; 00086 00087 #endif 00088 00089 } 00090 00091 //Public Function 4357 00092 double Timer::GetProcessorTime() 00093 { 00094 00095 #ifdef SYSTEM_TIME 00096 00097 double t_UserTime = (double) (tms_EndTimer.tms_utime - tms_BeginTimer.tms_utime) / CLK_TCK; 00098 double t_SystemTime = (double) (tms_EndTimer.tms_stime - tms_BeginTimer.tms_stime) / CLK_TCK; 00099 00100 return(t_UserTime + t_SystemTime); 00101 00102 #else 00103 00104 return(_UNKNOWN); 00105 00106 #endif 00107 00108 } 00109 00110 //Public Function 4358 00111 double Timer::GetUserProcessorTime() 00112 { 00113 00114 #ifdef SYSTEM_TIME 00115 00116 double t_UserTime = (double)(tms_EndTimer.tms_utime - tms_BeginTimer.tms_utime) / CLK_TCK; 00117 00118 return(t_UserTime); 00119 00120 #else 00121 00122 return(_UNKNOWN); 00123 00124 #endif 00125 00126 } 00127 00128 //Public Function 4359 00129 double Timer::GetSystemProcessorTime() 00130 { 00131 00132 #ifdef SYSTEM_TIME 00133 00134 double t_SystemTime = (double)(tms_EndTimer.tms_stime - tms_BeginTimer.tms_stime) / CLK_TCK; 00135 00136 return(t_SystemTime); 00137 00138 #else 00139 00140 return(_UNKNOWN); 00141 00142 #endif 00143 00144 } 00145 }