]> Dogcows Code - chaz/yoink/blob - src/stlplus/subsystems/timer.cpp
archiving support for releases
[chaz/yoink] / src / stlplus / subsystems / timer.cpp
1 ////////////////////////////////////////////////////////////////////////////////
2
3 // Author: Andy Rushton
4 // Copyright: (c) Southampton University 1999-2004
5 // (c) Andy Rushton 2004-2009
6 // License: BSD License, see ../docs/license.html
7
8 ////////////////////////////////////////////////////////////////////////////////
9 #include "timer.hpp"
10 #include "dprintf.hpp"
11 #include "time.hpp"
12
13 ////////////////////////////////////////////////////////////////////////////////
14
15 namespace stlplus
16 {
17
18 ////////////////////////////////////////////////////////////////////////////////
19
20 timer::timer(void)
21 {
22 reset();
23 }
24
25 timer::~timer(void)
26 {
27 }
28
29 void timer::reset(void)
30 {
31 m_clock = clock();
32 m_time = time(0);
33 }
34
35 float timer::cpu(void) const
36 {
37 return ((float)(clock() - m_clock)) / ((float)CLOCKS_PER_SEC);
38 }
39
40 float timer::elapsed(void) const
41 {
42 return ((float)(time(0) - m_time));
43 }
44
45 std::string timer::text(void) const
46 {
47 return dformat("%4.2fs CPU, %s elapsed", cpu(), delaytime_string(time(0)-m_time).c_str());
48 }
49
50 ////////////////////////////////////////////////////////////////////////////////
51
52 std::ostream& operator << (std::ostream& str, const timer& t)
53 {
54 return str << t.text();
55 }
56
57 ////////////////////////////////////////////////////////////////////////////////
58
59 } // end namespace stlplus
This page took 0.034508 seconds and 4 git commands to generate.