00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 1999-2008 Soeren Sonnenburg 00008 * Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #include "lib/Time.h" 00012 #include "lib/io.h" 00013 #include "lib/common.h" 00014 00015 CTime::CTime(bool st) 00016 : CSGObject() 00017 { 00018 start_time=0; 00019 stop_time=0; 00020 start_runtime=0; 00021 00022 if (st) 00023 start(); 00024 } 00025 00026 CTime::~CTime() 00027 { 00028 } 00029 00030 clock_t CTime::cur_runtime(bool verbose) 00031 { 00032 clock_t cur_time=clock(); 00033 if (verbose) 00034 SG_INFO( "current %ld\n", (LONG) cur_time); 00035 return cur_time; 00036 } 00037 00038 clock_t CTime::cur_runtime_diff(bool verbose) 00039 { 00040 clock_t diff=clock()-start_runtime; 00041 if (verbose) 00042 SG_INFO( "current diff %ld\n", (LONG) diff); 00043 return diff; 00044 } 00045 00046 double CTime::cur_runtime_diff_sec(bool verbose) 00047 { 00048 double diff_s = ((double)(clock() - start_runtime)) / CLOCKS_PER_SEC; 00049 if (verbose) 00050 SG_INFO( "%2.1f seconds\n", diff_s); 00051 00052 return diff_s; 00053 } 00054 00055 00056 double CTime::start(bool verbose) 00057 { 00058 start_time=get_curtime(); 00059 00060 if (verbose) 00061 SG_INFO( "start %ld\n", (LONG) start_time); 00062 return start_time; 00063 } 00064 00065 double CTime::cur_time_diff(bool verbose) 00066 { 00067 double diff_s = get_curtime()-start_time; 00068 if (verbose) 00069 SG_INFO( "%2.1f seconds\n", diff_s); 00070 00071 return diff_s; 00072 } 00073 00074 double CTime::time_diff_sec(bool verbose) 00075 { 00076 double diff_s = stop_time - start_time; 00077 if (verbose) 00078 SG_INFO( "%2.1f seconds\n", diff_s); 00079 00080 return diff_s; 00081 } 00082 00083 double CTime::stop(bool verbose) 00084 { 00085 stop_time=get_curtime(); 00086 00087 if (verbose) 00088 SG_INFO( "stop %ld\n", (LONG) stop_time); 00089 return stop_time; 00090 }