BTiming¶
Defined in header <BUtils/BTiming>
Overview¶
Class BTiming provides a timing system to record time with a minimum precision of 1 microsecond.
Public Types¶
enum | BTimingStatus {CPUTiming, Timing, Stop} |
Public Functions¶
BTiming() noexcept |
|
~BTiming() |
|
void | start() |
void | stop() |
void | startCPUTiming() |
void | stopCPUTiming() |
bool | isActive() |
int64 | time() const |
int64 | CPUTime() const |
Detailed Description¶
Class BTiming provides a timing system to record time with a minimum precision of 1 microsecond.
BTiming can record both real time and CPU time with the same minimum precision of 1 microsecond.
Example for timing one second:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <BUtils/BTiming>
#include <unistd.h>
#include <iostream>
int main() {
BUtils::BTiming timing;
BUtils::BTiming CPUTiming;
timing.start();
CPUTiming.startCPUTiming();
sleep(1);
timing.stop();
CPUTiming.stopCPUTiming();
std::cout << "Real time is: " << timing.time() << " us" << std::endl;
std::cout << "CPU time is: " << CPUTiming.CPUTime() << " us" << std::endl;
}
|
Member Type Documentation¶
-
enum
BTimingStatus
¶
Constant | Value | Description |
---|---|---|
BTiming::CPUTiming | 0 | Represents recording CPU time. |
BTiming::Timing | 1 | Represents recording real time. |
BTiming::Stop | 2 | Stopped recording. |
Member Function Documentation¶
Construct a BTiming object.
-
BTiming
::
~BTiming
()¶
Destruct a BTiming object.
-
void
BTiming
::
start
()¶
Start recording real time. Takes no effects if startCPUTiming is called.
-
void
BTiming
::
stop
()¶
Stop recording real time. Takes no effects if startCPUTiming is called.
-
void
BTiming
::
startCPUTiming
()¶
Start recording CPU time. Takes no effects if start is called.
-
void
BTiming
::
stopCPUTiming
()¶
Stop recording CPU time. Takes no effects if start is called.
-
bool
BTiming
::
isActive
()¶
Returns true if timing.
-
int64
BTiming
::
time
() const¶
Returns the real time recorded by calling start and stop in microseconds; otherwise returns 0.
-
int64
BTiming
::
CPUTime
() const¶
Returns the CPU time recorded by calling startCPUTiming and stopCPUTiming in microseconds; otherwise returns 0.