Time.cpp

Go to the documentation of this file.
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 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_PRINT("current %ld\n", (int64_t) 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_PRINT("current diff %ld\n", (int64_t) diff);
00043     return diff;
00044 }
00045 
00046 float64_t CTime::cur_runtime_diff_sec(bool verbose)
00047 {
00048     float64_t diff_s = ((float64_t)(clock() - start_runtime)) / CLOCKS_PER_SEC;
00049     if (verbose)
00050         SG_PRINT("%2.1f seconds\n", diff_s);
00051 
00052     return diff_s;
00053 }
00054 
00055 
00056 float64_t CTime::start(bool verbose)
00057 {
00058     start_time=get_curtime();
00059 
00060     if (verbose)
00061         SG_PRINT("start %ld\n", (int64_t) start_time);
00062     return start_time;
00063 }
00064 
00065 float64_t CTime::cur_time_diff(bool verbose)
00066 {
00067     float64_t diff_s = get_curtime()-start_time;
00068     if (verbose)
00069         SG_PRINT("%2.1f seconds\n", diff_s);
00070 
00071     return diff_s;
00072 }
00073 
00074 float64_t CTime::time_diff_sec(bool verbose)
00075 {
00076     float64_t diff_s = stop_time - start_time;
00077     if (verbose)
00078         SG_PRINT("%2.1f seconds\n", diff_s);
00079 
00080     return diff_s;
00081 }
00082 
00083 float64_t CTime::stop(bool verbose)
00084 {
00085     stop_time=get_curtime();
00086 
00087     if (verbose)
00088         SG_PRINT("stop %ld\n", (int64_t) stop_time);
00089     return stop_time;
00090 }

SHOGUN Machine Learning Toolbox - Documentation