csutil/measuretime.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

csutil/measuretime.h
Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2004-2006 by Jorrit Tyberghein
    00003               (C) 2004-2006 by Frank Richter
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Library General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public
    00016     License along with this library; if not, write to the Free
    00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00018 */
    00019
    00020 #ifndef __CS_CSUTIL_TIMEMEASURE_H__
    00021 #define __CS_CSUTIL_TIMEMEASURE_H__
    00022
    00027 #include "csutil/csstring.h"
    00028 #include "csutil/util.h"
    00029 #include "csutil/sysfunc.h"
    00030
    00031 namespace CS
    00032 {
    00033
    00054   class CS_CRYSTALSPACE_EXPORT MeasureTime
    00055   {
    00056   protected:
    00057     int64 offsetTime;
    00058     csString text;
    00059     void PrintTime (const char* prefix, int64 time, const char* suffix);
    00060   public:
    00064     MeasureTime (const char* format, ...)
    00065     {
    00066       va_list args;
    00067       va_start (args, format);
    00068       text.FormatV (format, args);
    00069       va_end (args);
    00070
    00071       offsetTime = csGetMicroTicks ();
    00072     }
    00073
    00074     ~MeasureTime ()
    00075     {
    00076       csTicks endTime = csGetMicroTicks ();
    00077       PrintTime ((text + ": ").GetData(), endTime - offsetTime,
    00078         " \xC2\xB5s\n");
    00079     }
    00080
    00082     void PrintIntermediate (const char* descr, ...)
    00083     {
    00084       int64 currentTime = csGetMicroTicks ();
    00085
    00086       csPrintf ("(%s)", text.GetData());
    00087       va_list args;
    00088       va_start (args, descr);
    00089       csPrintfV (descr, args);
    00090       va_end (args);
    00091       PrintTime (": ", currentTime - offsetTime, " \xC2\xB5s\n");
    00092
    00093       int64 currentTime2 = csGetMicroTicks ();
    00094       // Correct difference from printing
    00095       offsetTime += currentTime2 - currentTime;
    00096     }
    00097   };
    00098
    00101 } // namespace CS
    00102
    00103 #endif