| 
									
										
										
										
											2013-08-07 18:56:35 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *  Created by Phil on 05/08/2013. | 
					
						
							|  |  |  |  *  Copyright 2013 Two Blue Cubes Ltd. All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Distributed under the Boost Software License, Version 1.0. (See accompanying | 
					
						
							|  |  |  |  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "catch_timer.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-16 19:08:39 +01:00
										 |  |  | #include "catch_platform.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-07 18:56:35 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __clang__
 | 
					
						
							|  |  |  | #pragma clang diagnostic push
 | 
					
						
							|  |  |  | #pragma clang diagnostic ignored "-Wc++11-long-long"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 19:08:39 +01:00
										 |  |  | #ifdef CATCH_PLATFORM_WINDOWS
 | 
					
						
							| 
									
										
										
										
											2013-08-07 18:56:35 +01:00
										 |  |  | #include <windows.h>
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #include <sys/time.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Catch { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     namespace { | 
					
						
							| 
									
										
										
										
											2013-08-16 19:08:39 +01:00
										 |  |  | #ifdef CATCH_PLATFORM_WINDOWS
 | 
					
						
							| 
									
										
										
										
											2013-08-07 18:56:35 +01:00
										 |  |  |         uint64_t getCurrentTicks() { | 
					
						
							|  |  |  |             static uint64_t hz=0, hzo=0; | 
					
						
							|  |  |  |             if (!hz) { | 
					
						
							| 
									
										
										
										
											2015-03-04 19:00:29 +00:00
										 |  |  |                 QueryPerformanceFrequency( reinterpret_cast<LARGE_INTEGER*>( &hz ) ); | 
					
						
							|  |  |  |                 QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &hzo ) ); | 
					
						
							| 
									
										
										
										
											2013-08-07 18:56:35 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |             uint64_t t; | 
					
						
							| 
									
										
										
										
											2015-03-04 19:00:29 +00:00
										 |  |  |             QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &t ) ); | 
					
						
							| 
									
										
										
										
											2013-08-07 18:56:35 +01:00
										 |  |  |             return ((t-hzo)*1000000)/hz; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |         uint64_t getCurrentTicks() { | 
					
						
							|  |  |  |             timeval t; | 
					
						
							| 
									
										
										
										
											2015-07-01 07:33:27 +01:00
										 |  |  |             gettimeofday(&t,CATCH_NULL); | 
					
						
							| 
									
										
										
										
											2014-07-09 07:35:34 +01:00
										 |  |  |             return static_cast<uint64_t>( t.tv_sec ) * 1000000ull + static_cast<uint64_t>( t.tv_usec ); | 
					
						
							| 
									
										
										
										
											2013-08-07 18:56:35 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void Timer::start() { | 
					
						
							|  |  |  |         m_ticks = getCurrentTicks(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-03 19:20:23 +01:00
										 |  |  |     unsigned int Timer::getElapsedMicroseconds() const { | 
					
						
							| 
									
										
										
										
											2014-07-09 07:35:34 +01:00
										 |  |  |         return static_cast<unsigned int>(getCurrentTicks() - m_ticks); | 
					
						
							| 
									
										
										
										
											2013-08-07 18:56:35 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     unsigned int Timer::getElapsedMilliseconds() const { | 
					
						
							| 
									
										
										
										
											2014-09-03 19:20:23 +01:00
										 |  |  |         return static_cast<unsigned int>(getElapsedMicroseconds()/1000); | 
					
						
							| 
									
										
										
										
											2013-08-07 18:56:35 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     double Timer::getElapsedSeconds() const { | 
					
						
							| 
									
										
										
										
											2014-09-03 19:20:23 +01:00
										 |  |  |         return getElapsedMicroseconds()/1000000.0; | 
					
						
							| 
									
										
										
										
											2013-08-07 18:56:35 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace Catch
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef __clang__
 | 
					
						
							|  |  |  | #pragma clang diagnostic pop
 | 
					
						
							|  |  |  | #endif
 |