forked from stepcode/stepcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsc_benchmark.h
More file actions
77 lines (62 loc) · 2 KB
/
sc_benchmark.h
File metadata and controls
77 lines (62 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef SC_BENCHMARK_H
#define SC_BENCHMARK_H
/// \file sc_benchmark.h memory info, timers, etc for benchmarking
#include "sc_export.h"
#ifdef __cplusplus
#include <iostream>
#include <iosfwd>
#include <string>
#include "sc_memmgr.h"
extern "C" {
#endif
typedef struct {
long virtMemKB, physMemKB, userMilliseconds, sysMilliseconds;
} benchVals;
/** return a benchVals struct with four current statistics for this process:
* virtual and physical memory use in kb,
* user and system cpu time in ms
*
* not yet implemented for OSX or Windows.
*/
SC_BASE_EXPORT benchVals getMemAndTime( );
#ifdef __cplusplus
}
/** reports the difference in memory and cpu use between when the
* constructor is called and when stop() or the destructor is called.
*
* if the destructor is called and stop() had not previously been
* called, the results are printed to the ostream given in the
* constructor, prefixed by the description.
*
* depends on getMemAndTime() above - may not work on all platforms.
*/
class SC_BASE_EXPORT benchmark {
protected:
benchVals initialVals, laterVals;
#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable: 4251 )
#endif
std::ostream & ostr;
std::string descr;
#ifdef _MSC_VER
#pragma warning( pop )
#endif
bool debug, stopped;
public:
benchmark( std::string description = "", bool debugMessages = true, std::ostream & o_stream = std::cout );
/// if 'stopped' is false, uses str(true) to print to ostream
~benchmark( );
void reset( );
void reset( std::string description );
benchVals get( );
void stop( );
/// converts data member 'laterVals' into a string and returns it
std::string str( );
/// outputs result of str() on ostream 'ostr'
void out( );
/// converts 'bv' into a string, prefixed by data member 'descr'
std::string str( const benchVals & bv );
};
#endif //__cplusplus
#endif //SC_BENCHMARK_H