source: src/Helpers/Chronos.cpp@ 93abe8

Last change on this file since 93abe8 was 93abe8, checked in by Frederik Heber <heber@…>, 15 years ago

Added static and private object counter Info::NumberInfos.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * Chronos.cpp
10 *
11 * Created on: Mar 14, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "MemDebug.hpp"
21
22#include <iostream>
23
24#include "Chronos.hpp"
25
26#include "Singleton_impl.hpp"
27
28Chronos::Chronos()
29{}
30
31Chronos::~Chronos()
32{}
33
34int Chronos::getTime(const std::string _name) const
35{
36 // only those functions have a time that have run already
37 if (IsTimeRunning.count(_name)) {
38 // return -1 if function is currently running
39 if (!IsTimeRunning.count(_name))
40 return AccountedTime.at(_name);
41 else
42 return -1;
43 }
44 return 0;
45}
46
47void Chronos::resetTime(const std::string _name)
48{
49 if (IsTimeRunning.count(_name)) {
50 AccountedTime[_name] = 0;
51 }
52}
53
54void Chronos::startTiming(const std::string _name)
55{
56 // start time keeping
57 IsTimeRunning[_name] = true;
58}
59
60void Chronos::endTiming(const std::string _name)
61{
62 // finish time keeping if present
63 ASSERT(IsTimeRunning.count(_name), "Chronos::endTiming() - no timer under "+_name+" running.");
64 IsTimeRunning[_name] = false;
65}
66
67int Chronos::SumUpTotalTime() const
68{
69 int sum = 0;
70 for (TimekeepingMap::const_iterator iter = AccountedTime.begin();
71 iter != AccountedTime.end();
72 ++iter) {
73 sum += iter->second;
74 }
75 return sum;
76}
77
78size_t Chronos::SumUpTotalFunctions() const
79{
80 return IsTimeRunning.size();
81}
82
83std::ostream& operator<<(std::ostream &ost, const Chronos &_time)
84{
85 int sum = _time.SumUpTotalTime();
86 ost << "Total time passed: " << sum << std::endl;
87 ost << "Total functions: " << _time.SumUpTotalFunctions() << std::endl;
88
89 return ost;
90}
91
92
93CONSTRUCT_SINGLETON(Chronos)
Note: See TracBrowser for help on using the repository browser.