/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * Chronos.cpp * * Created on: Mar 14, 2011 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "MemDebug.hpp" #include #include "Chronos.hpp" #include "Singleton_impl.hpp" Chronos::Chronos() {} Chronos::~Chronos() {} int Chronos::getTime(const std::string _name) const { // only those functions have a time that have run already if (IsTimeRunning.count(_name)) { // return -1 if function is currently running if (!IsTimeRunning.count(_name)) return AccountedTime.at(_name); else return -1; } return 0; } void Chronos::resetTime(const std::string _name) { if (IsTimeRunning.count(_name)) { AccountedTime[_name] = 0; } } void Chronos::startTiming(const std::string _name) { // start time keeping IsTimeRunning[_name] = true; } void Chronos::endTiming(const std::string _name) { // finish time keeping if present ASSERT(IsTimeRunning.count(_name), "Chronos::endTiming() - no timer under "+_name+" running."); IsTimeRunning[_name] = false; } int Chronos::SumUpTotalTime() const { int sum = 0; for (TimekeepingMap::const_iterator iter = AccountedTime.begin(); iter != AccountedTime.end(); ++iter) { sum += iter->second; } return sum; } size_t Chronos::SumUpTotalFunctions() const { return IsTimeRunning.size(); } std::ostream& operator<<(std::ostream &ost, const Chronos &_time) { int sum = _time.SumUpTotalTime(); ost << "Total time passed: " << sum << std::endl; ost << "Total functions: " << _time.SumUpTotalFunctions() << std::endl; return ost; } CONSTRUCT_SINGLETON(Chronos)