mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-11-04 14:09:33 +01:00 
			
		
		
		
	Timer resolution is now nanoseconds
This commit is contained in:
		@@ -12,8 +12,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace Catch {
 | 
					namespace Catch {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    auto getCurrentMicrosecondsSinceEpoch() -> uint64_t {
 | 
					    auto getCurrentNanosecondsSinceEpoch() -> uint64_t {
 | 
				
			||||||
        return std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
 | 
					        return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace Catch
 | 
					} // namespace Catch
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,16 +12,19 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace Catch {
 | 
					namespace Catch {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    auto getCurrentMicrosecondsSinceEpoch() -> uint64_t;
 | 
					    auto getCurrentNanosecondsSinceEpoch() -> uint64_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class Timer {
 | 
					    class Timer {
 | 
				
			||||||
        uint64_t m_microSeconds = 0;
 | 
					        uint64_t m_nanoseconds = 0;
 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
        void start() {
 | 
					        void start() {
 | 
				
			||||||
           m_microSeconds = getCurrentMicrosecondsSinceEpoch();
 | 
					           m_nanoseconds = getCurrentNanosecondsSinceEpoch();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        auto getElapsedNanoseconds() const -> unsigned int {
 | 
				
			||||||
 | 
					            return static_cast<unsigned int>(getCurrentNanosecondsSinceEpoch() - m_nanoseconds);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        auto getElapsedMicroseconds() const -> unsigned int {
 | 
					        auto getElapsedMicroseconds() const -> unsigned int {
 | 
				
			||||||
            return static_cast<unsigned int>(getCurrentMicrosecondsSinceEpoch() - m_microSeconds);
 | 
					            return static_cast<unsigned int>(getElapsedNanoseconds()/1000);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        auto getElapsedMilliseconds() const -> unsigned int {
 | 
					        auto getElapsedMilliseconds() const -> unsigned int {
 | 
				
			||||||
            return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
 | 
					            return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user