feisty meow concerns codebase
2.140
test_stopwatch.cpp
Go to the documentation of this file.
1
// Name : test_stopwatch
3
// Author : Chris Koeritz
4
// Rights : Copyright (c) 1991-$now By Author
6
// This file is free software; you can modify/redistribute it under the terms
7
// of the GNU General Public License. [ http://www.gnu.org/licenses/gpl.html ]
8
// Feel free to send updates to: [ fred@gruntose.com ]
10
11
#include <
application/application_shell.h
>
12
#include <
application/hoople_main.h
>
13
#include <
basis/functions.h
>
14
#include <
basis/guards.h
>
15
#include <
loggers/console_logger.h
>
16
#include <
loggers/critical_events.h
>
17
#include <
loggers/program_wide_logger.h
>
18
#include <
mathematics/chaos.h
>
19
#include <
structures/static_memory_gremlin.h
>
20
#include <
timely/stopwatch.h
>
21
#include <
timely/time_control.h
>
22
23
using namespace
basis
;
24
using namespace
application
;
25
using namespace
loggers
;
26
using namespace
mathematics
;
27
using namespace
structures
;
28
using namespace
timely
;
29
30
#define DEBUG_TIMER
31
32
// ACCEPT: acceptable timer deviation from the total time to wait.
33
// NOTE: timer characteristics and the sleep characteristics for machines vary.
34
// it may be necessary to play with ACCEPT to get this program to accept the
35
// machine's particular characteristics.
36
//#define ACCEPT 0.01
37
//#define WIDER_ACCEPT 0.05
38
//#define WIDEST_ACCEPT 0.20
39
#define ACCEPT 0.9
40
#define WIDER_ACCEPT 0.95
41
#define WIDEST_ACCEPT 1.20
42
43
#define LOG(s) EMERGENCY_LOG(program_wide_logger::get(), s)
44
45
class
test_stopwatch :
public
application_shell
46
{
47
public
:
48
test_stopwatch() :
application_shell
() {}
49
DEFINE_CLASS_NAME
(
"test_stopwatch"
);
50
virtual
int
execute();
51
};
52
53
int
test_stopwatch::execute()
54
{
55
stopwatch
fred_time;
56
chaos
randomizer
;
57
58
int
to_sleep =
randomizer
.inclusive(20, 100);
59
// needs longer ints for the last two checks...
60
fred_time.
start
();
61
time_control::sleep_ms(to_sleep);
62
fred_time.
halt
();
63
#ifdef DEBUG_TIMER
64
LOG
(
a_sprintf
(
"sleep of %0.3f seconds took %d milliseconds\n"
,
65
float
(to_sleep) / 1000.0, fred_time.
milliseconds
()));
66
#endif
67
if
(
absolute_value
(to_sleep - fred_time.
milliseconds
())
68
>
ACCEPT
* to_sleep)
69
deadly_error
(class_name(),
"first"
,
"unacceptable timer deviation"
);
70
fred_time.
reset
();
71
72
to_sleep =
randomizer
.inclusive(76, 420);
73
fred_time.
start
();
74
time_control::sleep_ms(to_sleep);
75
fred_time.
halt
();
76
#ifdef DEBUG_TIMER
77
LOG
(
a_sprintf
(
"sleep of %0.3f seconds took %d milliseconds\n"
,
78
float
(to_sleep) / 1000.0, fred_time.
milliseconds
()));
79
#endif
80
if
(
absolute_value
(to_sleep - fred_time.
milliseconds
()) >
ACCEPT
* to_sleep)
81
deadly_error
(class_name(),
"second"
,
"unacceptable timer deviation"
);
82
fred_time.
reset
();
83
84
critical_events::alert_message(
"stopwatch:: works for those functions tested."
);
85
return
0;
86
}
87
88
HOOPLE_MAIN
(test_stopwatch, )
89
application_shell.h
chaos.h
application::application_shell
The application_shell is a base object for console programs.
Definition:
application_shell.h:33
basis::a_sprintf
a_sprintf is a specialization of astring that provides printf style support.
Definition:
astring.h:440
mathematics::chaos
a platform-independent way to acquire random numbers in a specific range.
Definition:
chaos.h:51
timely::stopwatch
A class for measuring event durations in real time.
Definition:
stopwatch.h:29
timely::stopwatch::milliseconds
int milliseconds()
Returns the elapsed number of milliseconds on the stopwatch, overall.
Definition:
stopwatch.cpp:59
timely::stopwatch::halt
void halt()
Stops the timing.
Definition:
stopwatch.cpp:71
timely::stopwatch::reset
void reset()
Stops the stopwatch and clears it to zero time elapsed.
Definition:
stopwatch.cpp:57
timely::stopwatch::start
void start()
Begins the timing.
Definition:
stopwatch.cpp:61
console_logger.h
critical_events.h
deadly_error
#define deadly_error(c, f, i)
Definition:
critical_events.h:87
DEFINE_CLASS_NAME
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition:
enhance_cpp.h:45
functions.h
guards.h
hoople_main.h
Provides macros that implement the 'main' program of an application.
HOOPLE_MAIN
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition:
hoople_main.h:61
application
Implements an application lock to ensure only one is running at once.
Definition:
application_shell.cpp:40
basis
The guards collection helps in testing preconditions and reporting errors.
Definition:
array.h:30
basis::absolute_value
type absolute_value(type a)
Returns a if a is non-negative, and returns -a otherwise.
Definition:
functions.h:33
loggers
A logger that sends to the console screen using the standard output device.
Definition:
combo_logger.cpp:36
mathematics
An extension to floating point primitives providing approximate equality.
Definition:
averager.h:21
structures
A dynamic container class that holds any kind of object via pointers.
Definition:
amorph.h:55
timely
#include <time.h>
Definition:
earth_time.cpp:37
program_wide_logger.h
static_memory_gremlin.h
stopwatch.h
randomizer
#define randomizer()
Definition:
t_bin_threaded.cpp:98
LOG
#define LOG(s)
Definition:
test_stopwatch.cpp:43
ACCEPT
#define ACCEPT
Definition:
test_stopwatch.cpp:39
time_control.h
nucleus
library
tests_timely
test_stopwatch.cpp
Generated by
1.9.1