1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef HIGH_RRSOLUTION_TIMER_H 16 #define HIGH_RRSOLUTION_TIMER_H 17 #include <iostream> 18 #include <chrono> 19 #include <thread> 20 namespace OHOS { 21 namespace AudioStandard { 22 namespace HPAE { 23 typedef std::chrono::high_resolution_clock::time_point TimePoint; 24 class HighResolutionTimer { 25 public: HighResolutionTimer()26 HighResolutionTimer() : startTime_(), endTime_() 27 {} 28 Start()29 void Start() 30 { 31 startTime_ = std::chrono::high_resolution_clock::now(); 32 } 33 Stop()34 void Stop() 35 { 36 endTime_ = std::chrono::high_resolution_clock::now(); 37 } 38 39 template <typename DurationType = std::chrono::milliseconds> Elapsed()40 auto Elapsed() const 41 { 42 return std::chrono::duration_cast<DurationType>(endTime_ - startTime_).count(); 43 } 44 45 private: 46 std::chrono::high_resolution_clock::time_point startTime_; 47 std::chrono::high_resolution_clock::time_point endTime_; 48 }; 49 50 } // namespace HPAE 51 } // namespace AudioStandard 52 } // namespace OHOS 53 54 #endif // __HIGH_RRSOLUTION_TIMER_H__