mirror of
https://codeberg.org/vcbferreira/NuFI_deal.ii
synced 2026-08-12 22:43:17 +02:00
added stop watch
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#ifndef STOPWATCH_H
|
||||
#define STOPWATCH_H
|
||||
|
||||
#include <chrono>
|
||||
|
||||
template <typename real>
|
||||
class stopwatch
|
||||
{
|
||||
public:
|
||||
void reset();
|
||||
real elapsed();
|
||||
|
||||
private:
|
||||
using clock = std::chrono::high_resolution_clock;
|
||||
clock::time_point t0 { clock::now() };
|
||||
};
|
||||
|
||||
|
||||
template <typename real> inline
|
||||
void stopwatch<real>::reset()
|
||||
{
|
||||
t0 = clock::now();
|
||||
}
|
||||
|
||||
template <typename real> inline
|
||||
real stopwatch<real>::elapsed()
|
||||
{
|
||||
using seconds = std::chrono::duration<real,std::ratio<1,1>>;
|
||||
|
||||
auto tnow = clock::now();
|
||||
auto duration = std::chrono::duration_cast<seconds>( tnow - t0 );
|
||||
|
||||
return duration.count();
|
||||
}
|
||||
|
||||
#endif // STOPWATCH_H
|
||||
|
||||
Reference in New Issue
Block a user