/// /// \author John Farrier /// /// \copyright Copyright 2015, 2016, 2017, 2018. 2019 John Farrier /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// #include #include #include #ifdef WIN32 #include LARGE_INTEGER QPCFrequency; #else #include #endif uint64_t celero::timer::GetSystemTime() { #ifdef WIN32 LARGE_INTEGER timeStorage; QueryPerformanceCounter(&timeStorage); if(QPCFrequency.QuadPart != 0) { return static_cast(timeStorage.QuadPart * 1000000) / static_cast(QPCFrequency.QuadPart); } return 0; #else auto timePoint = std::chrono::high_resolution_clock::now(); return std::chrono::duration_cast(timePoint.time_since_epoch()).count(); #endif } double celero::timer::CachePerformanceFrequency(bool quiet) { #ifdef WIN32 QueryPerformanceFrequency(&QPCFrequency); if(QPCFrequency.QuadPart == 0) { return 0; } auto precision = ((1.0 / static_cast(QPCFrequency.QuadPart)) * 1000000.0); #else if(static_cast(std::chrono::high_resolution_clock::period::den) == 0) { return 0; } auto precision = (static_cast(std::chrono::high_resolution_clock::period::num) / static_cast(std::chrono::high_resolution_clock::period::den)) * 1000000.0; #endif if(quiet == false) { std::cout << "Timer resolution: " << std::to_string(precision) << " us" << std::endl; } return precision; }