35 lines
860 B
C++
35 lines
860 B
C++
#pragma once
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <osg/Timer>
|
|
|
|
class ScopedTimer {
|
|
public:
|
|
ScopedTimer(const std::string& description,
|
|
std::ostream& output_stream = std::cout,
|
|
bool endline_after_time = true)
|
|
: outputStream_(output_stream)
|
|
, start_()
|
|
, endlineAfterTime_(endline_after_time) {
|
|
outputStream_ << description << std::flush;
|
|
start_ = osg::Timer::instance()->tick();
|
|
}
|
|
|
|
~ScopedTimer() {
|
|
osg::Timer_t end = osg::Timer::instance()->tick();
|
|
|
|
outputStream_ << osg::Timer::instance()->delta_s(start_, end) << "s";
|
|
|
|
if (endlineAfterTime_) {
|
|
outputStream_ << std::endl;
|
|
} else {
|
|
outputStream_ << std::flush;
|
|
}
|
|
}
|
|
|
|
private:
|
|
std::ostream& outputStream_;
|
|
osg::Timer_t start_;
|
|
bool endlineAfterTime_;
|
|
}; |