hrtimer_8cpp-source.html

来自「Crypto++是一个非常强大的密码学库,主要是功能全」· HTML 代码 · 共 89 行

HTML
89
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Crypto++: hrtimer.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.2 --><div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Compound&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Compound&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div><h1>hrtimer.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// hrtimer.cpp - written and placed in the public domain by Wei Dai</span>00002 00003 <span class="preprocessor">#include "pch.h"</span>00004 <span class="preprocessor">#include "hrtimer.h"</span>00005 <span class="preprocessor">#include &lt;stddef.h&gt;</span>             <span class="comment">// for NULL</span>00006 00007 <span class="preprocessor">#ifdef HIGHRES_TIMER_AVAILABLE</span>00008 <span class="preprocessor"></span>00009 <span class="preprocessor">#if defined(CRYPTOPP_WIN32_AVAILABLE)</span>00010 <span class="preprocessor"></span><span class="preprocessor">#include &lt;windows.h&gt;</span>00011 <span class="preprocessor">#elif defined(__unix__)</span>00012 <span class="preprocessor"></span><span class="preprocessor">#include &lt;sys/time.h&gt;</span>00013 <span class="preprocessor">#elif defined(macintosh)</span>00014 <span class="preprocessor"></span><span class="preprocessor">#include &lt;Timer.h&gt;</span>00015 <span class="preprocessor">#endif</span>00016 <span class="preprocessor"></span>00017 <span class="preprocessor">#include &lt;assert.h&gt;</span>00018 00019 NAMESPACE_BEGIN(CryptoPP)00020 00021 word64 Timer::GetCurrentTimerValue()00022 {00023 <span class="preprocessor">#if defined(CRYPTOPP_WIN32_AVAILABLE)</span>00024 <span class="preprocessor"></span>        FILETIME now;00025         GetSystemTimeAsFileTime(&amp;now);00026         <span class="keywordflow">return</span> now.dwLowDateTime + ((word64)now.dwHighDateTime &lt;&lt; 32);00027 <span class="preprocessor">#elif defined(__unix__)</span>00028 <span class="preprocessor"></span>        timeval now;00029         gettimeofday(&amp;now, NULL);00030         <span class="keywordflow">return</span> (word64)now.tv_sec * 1000000 + now.tv_usec;00031 <span class="preprocessor">#elif defined(macintosh)</span>00032 <span class="preprocessor"></span>        UnsignedWide now;00033         Microseconds(&amp;now);00034         <span class="keywordflow">return</span> now.lo + ((word64)now.hi &lt;&lt; 32);00035 <span class="preprocessor">#endif</span>00036 <span class="preprocessor"></span>}00037 00038 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> Timer::ConvertTo(word64 t, Unit unit)00039 {00040         <span class="keywordflow">switch</span> (unit)00041         {00042         <span class="keywordflow">case</span> SECONDS:00043                 <span class="keywordflow">return</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)(t / (TicksPerMillisecond() * 1000));00044         <span class="keywordflow">case</span> MILLISECONDS:00045                 <span class="keywordflow">return</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)(t / TicksPerMillisecond());00046         <span class="keywordflow">case</span> MICROSECONDS:00047                 assert(TicksPerMillisecond() % 1000 == 0);00048                 <span class="keywordflow">return</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)(t / (TicksPerMillisecond() / 1000));00049         }00050         assert(<span class="keyword">false</span>);00051         <span class="keywordflow">return</span> 0;00052 }00053 00054 <span class="keywordtype">void</span> Timer::StartTimer()00055 {00056         m_start = GetCurrentTimerValue();00057         m_started = <span class="keyword">true</span>;00058 }00059 00060 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> Timer::ElapsedTime()00061 {00062         <span class="keywordflow">if</span> (m_stuckAtZero)00063                 <span class="keywordflow">return</span> 0;00064         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (m_started)00065                 <span class="keywordflow">return</span> ConvertTo(GetCurrentTimerValue() - m_start, m_timerUnit);00066         <span class="keywordflow">else</span>00067         {00068                 StartTimer();00069                 <span class="keywordflow">return</span> 0;00070         }00071 }00072 00073 NAMESPACE_END00074 00075 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:16 2003 for Crypto++ by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.2 </small></address></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?