Timer.hh
Go to the documentation of this file.
/* ========================================================================= *
* *
* OpenMesh *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openmesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenMesh. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= */
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* *
\*===========================================================================*/
#ifndef TIMER_HH
#define TIMER_HH
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#include <OpenMesh/Core/System/config.hh>
//
#include <ostream>
#include <string>
#if defined(OM_CC_MIPS)
# include <assert.h>
#else
# include <cassert>
#endif
// ------------------------------------------------------------- namespace ----
namespace OpenMesh {
namespace Utils {
// -------------------------------------------------------------- forwards ----
class TimerImpl;
// ----------------------------------------------------------------- class ----
class OPENMESHDLLEXPORT Timer
{
public:
enum Format {
Automatic,
Long,
Hours,
Minutes,
Seconds,
HSeconds,
MSeconds,
MicroSeconds,
NanoSeconds
};
Timer(void);
Timer(const Timer& _other) = delete;
~Timer(void);
bool is_valid() const { return state_!=Invalid; }
bool is_stopped() const { return state_==Stopped; }
void reset(void);
void start(void);
void stop(void);
void cont(void);
float resolution() const;
double seconds(void) const;
double hseconds(void) const { return seconds()*1e2; }
double mseconds(void) const { return seconds()*1e3; }
double useconds(void) const { return seconds()*1e6; }
std::string as_string(Format format = Automatic);
static std::string as_string(double seconds, Format format = Automatic);
public:
bool operator < (const Timer& t2) const
{
assert( is_stopped() && t2.is_stopped() );
return (seconds() < t2.seconds());
}
bool operator > (const Timer& t2) const
{
assert( is_stopped() && t2.is_stopped() );
return (seconds() > t2.seconds());
}
bool operator == (const Timer& t2) const
{
assert( is_stopped() && t2.is_stopped() );
return (seconds() == t2.seconds());
}
bool operator <= (const Timer& t2) const
{
assert( is_stopped() && t2.is_stopped() );
return (seconds() <= t2.seconds());
}
bool operator >=(const Timer& t2) const
{
assert( is_stopped() && t2.is_stopped() );
return (seconds() >= t2.seconds());
}
protected:
TimerImpl *impl_;
enum {
Invalid = -1,
Stopped = 0,
Running = 1
} state_;
};
inline std::ostream& operator << (std::ostream& _o, const Timer& _t)
{
return (_o << _t.seconds());
}
// ============================================================================
} // END_NS_UTILS
} // END_NS_OPENMESH
// ============================================================================
#endif
// end of Timer.hh
// ===========================================================================
OpenMesh::Utils::Timer::useconds
double useconds(void) const
Returns measured time in micro seconds, if the timer is in state &#39;Stopped&#39;.
Definition: Timer.hh:140
OpenMesh::operator<<
auto operator<<(std::ostream &os, const VectorT< Scalar, DIM > &_vec) -> typename std::enable_if< sizeof(decltype(os<< _vec[0])) >=0
output a vector by printing its space-separated compontens
OpenMesh::Utils::Timer
Timer class.
Definition: Timer.hh:87
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
OpenMesh::Utils::Timer::Format
Format
Formatting options for member Timer::as_string()
Definition: Timer.hh:92
OpenMesh::Utils::Timer::is_valid
bool is_valid() const
Returns true if self is in a valid state!
Definition: Timer.hh:111
OpenMesh::Utils::Timer::seconds
double seconds(void) const
Returns measured time in seconds, if the timer is in state &#39;Stopped&#39;.
OpenMesh::Utils::Timer::hseconds
double hseconds(void) const
Returns measured time in hundredth seconds, if the timer is in state &#39;Stopped&#39;.
Definition: Timer.hh:134
OpenMesh::Utils::Timer::mseconds
double mseconds(void) const
Returns measured time in milli seconds, if the timer is in state &#39;Stopped&#39;.
Definition: Timer.hh:137