File: ScopedTimer.hpp

package info (click to toggle)
salmon 0.7.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,352 kB
  • ctags: 5,243
  • sloc: cpp: 42,341; ansic: 6,252; python: 228; makefile: 207; sh: 190
file content (22 lines) | stat: -rw-r--r-- 567 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef __SCOPED_TIMER_HPP__
#define __SCOPED_TIMER_HPP__
// from https://gist.github.com/justgord/4482447
#include <chrono>
#include <iostream>

struct ScopedTimer
{
    std::chrono::high_resolution_clock::time_point t0;

    ScopedTimer()
        : t0(std::chrono::high_resolution_clock::now())
    { }
    ~ScopedTimer(void)
    {
        auto  t1 = std::chrono::high_resolution_clock::now();
        std::chrono::duration<double> elapsedSec =  t1 - t0;
        std::cerr << "Elapsed time: " << elapsedSec.count() << "s\n";
    }
};

#endif //__SCOPED_TIMER_HPP__