https://gitlab.opengeosys.org/ogs/ogs.git
Tip revision: c1d15ccd2c24fa4ce0d66051141d6d9a8ea01d6d authored by Lars Bilke on 11 March 2020, 14:28:06 UTC
Release notes 6.3.0
Release notes 6.3.0
Tip revision: c1d15cc
RunTime.h
/**
* \file
* \author Thomas Fischer
* \author Wenqing Wang
* \date 2012-05-10, 2014-10.10
* \brief Definition of the RunTime class.
*
* \copyright
* Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*/
#pragma once
#if defined(USE_MPI)
#include <mpi.h>
#else
#ifndef WIN32
#include <sys/time.h>
#else
#include <windows.h>
#endif
#endif
namespace BaseLib
{
/// Count the running time.
class RunTime
{
public:
/// Start the timer.
void start()
{
#if defined(USE_MPI)
_start_time = MPI_Wtime();
#else
#ifndef WIN32
timeval t;
gettimeofday(&t, nullptr);
_start_time = t.tv_sec + t.tv_usec/1000000.0;
#else
_start_time = timeGetTime();
#endif
#endif
}
/// Get the elapsed time after started.
double elapsed() const
{
#if defined(USE_MPI)
return MPI_Wtime() - _start_time;
#else
#ifndef WIN32
timeval t;
gettimeofday(&t, nullptr);
return t.tv_sec + t.tv_usec/1000000.0 - _start_time;
#else
return (timeGetTime() - _start_time)/1000.0;
#endif
#endif
}
private:
double _start_time = 0.;
};
} // end namespace BaseLib