]> git.sesse.net Git - casparcg/commitdiff
Reimplement caspar::timer without Boost.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 May 2017 19:31:32 +0000 (21:31 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 May 2017 19:31:32 +0000 (21:31 +0200)
common/timer.h

index ce4b3f319d690785e904f5a88291cfc6f247fdf9..b9bdd87addef72a220a3cb83565850e71ed2b639 100644 (file)
 
 #pragma once
 
-#include <boost/chrono/system_clocks.hpp>
+#include <chrono>
 
 namespace caspar {
 
 // Replacement of boost::timer because it uses std::clock which has very low resolution in linux.
 class timer
 {
-       boost::int_least64_t _start_time;
+       std::chrono::high_resolution_clock::time_point _start_time;
 public:
        timer()
        {
-               _start_time = now();
+               _start_time = std::chrono::high_resolution_clock::now();
        }
 
        void restart()
        {
-               _start_time = now();
+               _start_time = std::chrono::high_resolution_clock::now();
        }
 
        double elapsed() const
        {
-               return static_cast<double>(now() - _start_time) / 1000.0;
+               return std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - _start_time).count();
        }
 private:
-       static boost::int_least64_t now()
-       {
-               using namespace boost::chrono;
-
-               return duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
-       }
 };
 
 }