Listing 4 Extract from winstl_highperformance_counter.h
/* ///////////////////////////////////////////////////////////// * ... * * Extract from winstl_highperformance_counter.h * * Copyright (C) 2002, Synesis Software Pty Ltd. * (Licensed under the Synesis Software Standard Source License: * http://www.synesis.com.au/licenses/ssssl.html) * * ... * ////////////////////////////////////////////////////////// */ inline /* static */ highperformance_counter::interval_type highperformance_counter::_query_frequency() { interval_type frequency; // If no high-performance counter is available ... if( !::QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*> (&frequency)) || frequency == 0) { // ... then set the divisor to be the maximum value, guaranteeing that // the timed periods will always evaluate to 0. frequency = stlsoft_ns_qual(limit_traits)<interval_type>::maximum(); } return frequency; } inline /* static */ highperformance_counter::interval_type highperformance_counter::_frequency() { static interval_type s_frequency = _query_frequency(); return s_frequency; } // Operations inline void highperformance_counter::start() { ::QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&m_start)); } inline void highperformance_counter::stop() { ::QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&m_end)); } // Attributes inline highperformance_counter::interval_type highperformance_counter::get_seconds() const { return get_period_count() / _frequency(); } inline highperformance_counter::interval_type highperformance_counter::get_milliseconds() const { highperformance_counter::interval_type result; highperformance_counter::interval_type count = get_period_count(); if(count < __STLSOFT_GEN_SINT64_SUFFIX(0x20C49BA5E353F7)) { result = (count * interval_type(1000)) / _frequency(); } else { result = (count / _frequency()) * interval_type(1000); } return result; } inline highperformance_counter::interval_type highperformance_counter::get_microseconds() const { highperformance_counter::interval_type result; highperformance_counter::interval_type count = get_period_count(); if(count < __STLSOFT_GEN_SINT64_SUFFIX(0x8637BD05AF6)) { result = (count * interval_type(1000000)) / _frequency(); } else { result = (count / _frequency()) * interval_type(1000000); } return result; }