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-2009 Soeren Sonnenburg 00008 * Copyright (C) 1999-2009 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 using namespace shogun; 00016 00017 CTime::CTime(bool st) 00018 : CSGObject() 00019 { 00020 start_time=0; 00021 stop_time=0; 00022 start_runtime=0; 00023 00024 if (st) 00025 start(); 00026 } 00027 00028 CTime::~CTime() 00029 { 00030 } 00031 00032 clock_t CTime::cur_runtime(bool verbose) 00033 { 00034 clock_t cur_time=clock(); 00035 if (verbose) 00036 SG_PRINT("current %ld\n", (int64_t) cur_time); 00037 return cur_time; 00038 } 00039 00040 clock_t CTime::cur_runtime_diff(bool verbose) 00041 { 00042 clock_t diff=clock()-start_runtime; 00043 if (verbose) 00044 SG_PRINT("current diff %ld\n", (int64_t) diff); 00045 return diff; 00046 } 00047 00048 float64_t CTime::cur_runtime_diff_sec(bool verbose) 00049 { 00050 float64_t diff_s = ((float64_t)(clock() - start_runtime)) / CLOCKS_PER_SEC; 00051 if (verbose) 00052 SG_PRINT("%2.1f seconds\n", diff_s); 00053 00054 return diff_s; 00055 } 00056 00057 00058 float64_t CTime::start(bool verbose) 00059 { 00060 start_time=get_curtime(); 00061 00062 if (verbose) 00063 SG_PRINT("start %ld\n", (int64_t) start_time); 00064 return start_time; 00065 } 00066 00067 float64_t CTime::cur_time_diff(bool verbose) 00068 { 00069 float64_t diff_s = get_curtime()-start_time; 00070 if (verbose) 00071 SG_PRINT("%2.1f seconds\n", diff_s); 00072 00073 return diff_s; 00074 } 00075 00076 float64_t CTime::time_diff_sec(bool verbose) 00077 { 00078 float64_t diff_s = stop_time - start_time; 00079 if (verbose) 00080 SG_PRINT("%2.1f seconds\n", diff_s); 00081 00082 return diff_s; 00083 } 00084 00085 float64_t CTime::stop(bool verbose) 00086 { 00087 stop_time=get_curtime(); 00088 00089 if (verbose) 00090 SG_PRINT("stop %ld\n", (int64_t) stop_time); 00091 return stop_time; 00092 }