1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>tick_count.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.7 -->
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li id="current"><a href="files.html"><span>Files</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
</ul></div>
<div class="tabs">
<ul>
<li><a href="files.html"><span>File List</span></a></li>
<li><a href="globals.html"><span>File Members</span></a></li>
</ul></div>
<h1>tick_count.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> Copyright 2005-2010 Intel Corporation. All Rights Reserved.</span>
<a name="l00003"></a>00003 <span class="comment"></span>
<a name="l00004"></a>00004 <span class="comment"> The source code contained or described herein and all documents related</span>
<a name="l00005"></a>00005 <span class="comment"> to the source code ("Material") are owned by Intel Corporation or its</span>
<a name="l00006"></a>00006 <span class="comment"> suppliers or licensors. Title to the Material remains with Intel</span>
<a name="l00007"></a>00007 <span class="comment"> Corporation or its suppliers and licensors. The Material is protected</span>
<a name="l00008"></a>00008 <span class="comment"> by worldwide copyright laws and treaty provisions. No part of the</span>
<a name="l00009"></a>00009 <span class="comment"> Material may be used, copied, reproduced, modified, published, uploaded,</span>
<a name="l00010"></a>00010 <span class="comment"> posted, transmitted, distributed, or disclosed in any way without</span>
<a name="l00011"></a>00011 <span class="comment"> Intel's prior express written permission.</span>
<a name="l00012"></a>00012 <span class="comment"></span>
<a name="l00013"></a>00013 <span class="comment"> No license under any patent, copyright, trade secret or other</span>
<a name="l00014"></a>00014 <span class="comment"> intellectual property right is granted to or conferred upon you by</span>
<a name="l00015"></a>00015 <span class="comment"> disclosure or delivery of the Materials, either expressly, by</span>
<a name="l00016"></a>00016 <span class="comment"> implication, inducement, estoppel or otherwise. Any license under such</span>
<a name="l00017"></a>00017 <span class="comment"> intellectual property rights must be express and approved by Intel in</span>
<a name="l00018"></a>00018 <span class="comment"> writing.</span>
<a name="l00019"></a>00019 <span class="comment">*/</span>
<a name="l00020"></a>00020
<a name="l00021"></a>00021 <span class="preprocessor">#ifndef __TBB_tick_count_H</span>
<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#define __TBB_tick_count_H</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span>
<a name="l00024"></a>00024 <span class="preprocessor">#include "tbb_stddef.h"</span>
<a name="l00025"></a>00025
<a name="l00026"></a>00026 <span class="preprocessor">#if _WIN32||_WIN64</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#include <windows.h></span>
<a name="l00028"></a>00028 <span class="preprocessor">#elif __linux__</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <ctime></span>
<a name="l00030"></a>00030 <span class="preprocessor">#else </span><span class="comment">/* generic Unix */</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include <sys/time.h></span>
<a name="l00032"></a>00032 <span class="preprocessor">#endif </span><span class="comment">/* (choice of OS) */</span>
<a name="l00033"></a>00033
<a name="l00034"></a>00034 <span class="keyword">namespace </span>tbb {
<a name="l00035"></a>00035
<a name="l00037"></a>00037
<a name="l00038"></a><a class="code" href="a00210.html">00038</a> <span class="keyword">class </span><a class="code" href="a00210.html">tick_count</a> {
<a name="l00039"></a>00039 <span class="keyword">public</span>:
<a name="l00041"></a><a class="code" href="a00211.html">00041</a> <span class="keyword">class </span><a class="code" href="a00211.html">interval_t</a> {
<a name="l00042"></a>00042 <span class="keywordtype">long</span> <span class="keywordtype">long</span> value;
<a name="l00043"></a>00043 <span class="keyword">explicit</span> <a class="code" href="a00211.html#75a9a0949f8a8a84d6758835f1b48dad">interval_t</a>( <span class="keywordtype">long</span> <span class="keywordtype">long</span> value_ ) : value(value_) {}
<a name="l00044"></a>00044 <span class="keyword">public</span>:
<a name="l00046"></a><a class="code" href="a00211.html#75a9a0949f8a8a84d6758835f1b48dad">00046</a> <a class="code" href="a00211.html#75a9a0949f8a8a84d6758835f1b48dad">interval_t</a>() : value(0) {};
<a name="l00047"></a>00047
<a name="l00049"></a>00049 <span class="keyword">explicit</span> <a class="code" href="a00211.html#75a9a0949f8a8a84d6758835f1b48dad">interval_t</a>( <span class="keywordtype">double</span> sec );
<a name="l00050"></a>00050
<a name="l00052"></a>00052 <span class="keywordtype">double</span> <a class="code" href="a00211.html#d5d8429c0bc59cf6131b2abc7929fa59">seconds</a>() <span class="keyword">const</span>;
<a name="l00053"></a>00053
<a name="l00054"></a>00054 <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="a00210.html">tbb::tick_count</a>;
<a name="l00055"></a>00055
<a name="l00057"></a>00057 <span class="keyword">friend</span> <a class="code" href="a00211.html">interval_t</a> <a class="code" href="a00211.html#09dde78a4100800c11bb883d6204b586">operator-</a>( <span class="keyword">const</span> <a class="code" href="a00210.html">tick_count</a>& t1, <span class="keyword">const</span> <a class="code" href="a00210.html">tick_count</a>& t0 );
<a name="l00058"></a>00058
<a name="l00060"></a><a class="code" href="a00211.html#5871ead1ca230efbe52a5008470e6428">00060</a> <span class="keyword">friend</span> <a class="code" href="a00211.html">interval_t</a> <a class="code" href="a00211.html#5871ead1ca230efbe52a5008470e6428">operator+</a>( <span class="keyword">const</span> <a class="code" href="a00211.html">interval_t</a>& i, <span class="keyword">const</span> <a class="code" href="a00211.html">interval_t</a>& j ) {
<a name="l00061"></a>00061 <span class="keywordflow">return</span> <a class="code" href="a00211.html#75a9a0949f8a8a84d6758835f1b48dad">interval_t</a>(i.<a class="code" href="a00211.html#beea71acda120af3e3e29f10e8cb5c10">value</a>+j.<a class="code" href="a00211.html#beea71acda120af3e3e29f10e8cb5c10">value</a>);
<a name="l00062"></a>00062 }
<a name="l00063"></a>00063
<a name="l00065"></a><a class="code" href="a00211.html#fa509691e1d689830931e36edd274f76">00065</a> <span class="keyword">friend</span> <a class="code" href="a00211.html">interval_t</a> <a class="code" href="a00211.html#09dde78a4100800c11bb883d6204b586">operator-</a>( <span class="keyword">const</span> <a class="code" href="a00211.html">interval_t</a>& i, <span class="keyword">const</span> <a class="code" href="a00211.html">interval_t</a>& j ) {
<a name="l00066"></a>00066 <span class="keywordflow">return</span> <a class="code" href="a00211.html#75a9a0949f8a8a84d6758835f1b48dad">interval_t</a>(i.<a class="code" href="a00211.html#beea71acda120af3e3e29f10e8cb5c10">value</a>-j.<a class="code" href="a00211.html#beea71acda120af3e3e29f10e8cb5c10">value</a>);
<a name="l00067"></a>00067 }
<a name="l00068"></a>00068
<a name="l00070"></a><a class="code" href="a00211.html#cd9814947902e26463a69a111530f81b">00070</a> <a class="code" href="a00211.html">interval_t</a>& <a class="code" href="a00211.html#cd9814947902e26463a69a111530f81b">operator+=</a>( <span class="keyword">const</span> <a class="code" href="a00211.html">interval_t</a>& i ) {value += i.<a class="code" href="a00211.html#beea71acda120af3e3e29f10e8cb5c10">value</a>; <span class="keywordflow">return</span> *<span class="keyword">this</span>;}
<a name="l00071"></a>00071
<a name="l00073"></a><a class="code" href="a00211.html#35ff7eaf7c2031b4a991402ac9ecb940">00073</a> <a class="code" href="a00211.html">interval_t</a>& <a class="code" href="a00211.html#35ff7eaf7c2031b4a991402ac9ecb940">operator-=</a>( <span class="keyword">const</span> <a class="code" href="a00211.html">interval_t</a>& i ) {value -= i.<a class="code" href="a00211.html#beea71acda120af3e3e29f10e8cb5c10">value</a>; <span class="keywordflow">return</span> *<span class="keyword">this</span>;}
<a name="l00074"></a>00074 };
<a name="l00075"></a>00075
<a name="l00077"></a><a class="code" href="a00210.html#34593326ae4191e02a13c7cbdab9de4c">00077</a> <a class="code" href="a00210.html#34593326ae4191e02a13c7cbdab9de4c">tick_count</a>() : my_count(0) {};
<a name="l00078"></a>00078
<a name="l00080"></a>00080 <span class="keyword">static</span> <a class="code" href="a00210.html">tick_count</a> <a class="code" href="a00210.html#fb7f78ca61cf28398645ace66e284473">now</a>();
<a name="l00081"></a>00081
<a name="l00083"></a>00083 <span class="keyword">friend</span> interval_t <a class="code" href="a00210.html#09dde78a4100800c11bb883d6204b586">operator-</a>( <span class="keyword">const</span> <a class="code" href="a00210.html">tick_count</a>& t1, <span class="keyword">const</span> <a class="code" href="a00210.html">tick_count</a>& t0 );
<a name="l00084"></a>00084
<a name="l00085"></a>00085 <span class="keyword">private</span>:
<a name="l00086"></a>00086 <span class="keywordtype">long</span> <span class="keywordtype">long</span> my_count;
<a name="l00087"></a>00087 };
<a name="l00088"></a>00088
<a name="l00089"></a><a class="code" href="a00210.html#fb7f78ca61cf28398645ace66e284473">00089</a> <span class="keyword">inline</span> <a class="code" href="a00210.html">tick_count</a> <a class="code" href="a00210.html#fb7f78ca61cf28398645ace66e284473">tick_count::now</a>() {
<a name="l00090"></a>00090 <a class="code" href="a00210.html">tick_count</a> result;
<a name="l00091"></a>00091 <span class="preprocessor">#if _WIN32||_WIN64</span>
<a name="l00092"></a>00092 <span class="preprocessor"></span> LARGE_INTEGER qpcnt;
<a name="l00093"></a>00093 QueryPerformanceCounter(&qpcnt);
<a name="l00094"></a>00094 result.<a class="code" href="a00210.html#1ba05ad46dc08bc1bf34bd6cc94e36ec">my_count</a> = qpcnt.QuadPart;
<a name="l00095"></a>00095 <span class="preprocessor">#elif __linux__</span>
<a name="l00096"></a>00096 <span class="preprocessor"></span> <span class="keyword">struct </span>timespec ts;
<a name="l00097"></a>00097 <span class="preprocessor">#if TBB_USE_ASSERT</span>
<a name="l00098"></a>00098 <span class="preprocessor"></span> <span class="keywordtype">int</span> status =
<a name="l00099"></a>00099 <span class="preprocessor">#endif </span><span class="comment">/* TBB_USE_ASSERT */</span>
<a name="l00100"></a>00100 clock_gettime( CLOCK_REALTIME, &ts );
<a name="l00101"></a>00101 __TBB_ASSERT( status==0, <span class="stringliteral">"CLOCK_REALTIME not supported"</span> );
<a name="l00102"></a>00102 result.<a class="code" href="a00210.html#1ba05ad46dc08bc1bf34bd6cc94e36ec">my_count</a> = static_cast<long long>(1000000000UL)*static_cast<long long>(ts.tv_sec) + static_cast<long long>(ts.tv_nsec);
<a name="l00103"></a>00103 <span class="preprocessor">#else </span><span class="comment">/* generic Unix */</span>
<a name="l00104"></a>00104 <span class="keyword">struct </span>timeval tv;
<a name="l00105"></a>00105 <span class="preprocessor">#if TBB_USE_ASSERT</span>
<a name="l00106"></a>00106 <span class="preprocessor"></span> <span class="keywordtype">int</span> status =
<a name="l00107"></a>00107 <span class="preprocessor">#endif </span><span class="comment">/* TBB_USE_ASSERT */</span>
<a name="l00108"></a>00108 gettimeofday(&tv, NULL);
<a name="l00109"></a>00109 __TBB_ASSERT( status==0, <span class="stringliteral">"gettimeofday failed"</span> );
<a name="l00110"></a>00110 result.<a class="code" href="a00210.html#1ba05ad46dc08bc1bf34bd6cc94e36ec">my_count</a> = static_cast<long long>(1000000)*static_cast<long long>(tv.tv_sec) + static_cast<long long>(tv.tv_usec);
<a name="l00111"></a>00111 <span class="preprocessor">#endif </span><span class="comment">/*(choice of OS) */</span>
<a name="l00112"></a>00112 <span class="keywordflow">return</span> result;
<a name="l00113"></a>00113 }
<a name="l00114"></a>00114
<a name="l00115"></a><a class="code" href="a00211.html#1a21a428e00cced2e6a49e0f5f2258bf">00115</a> <span class="keyword">inline</span> <a class="code" href="a00211.html#75a9a0949f8a8a84d6758835f1b48dad">tick_count::interval_t::interval_t</a>( <span class="keywordtype">double</span> sec )
<a name="l00116"></a>00116 {
<a name="l00117"></a>00117 <span class="preprocessor">#if _WIN32||_WIN64</span>
<a name="l00118"></a>00118 <span class="preprocessor"></span> LARGE_INTEGER qpfreq;
<a name="l00119"></a>00119 QueryPerformanceFrequency(&qpfreq);
<a name="l00120"></a>00120 value = static_cast<long long>(sec*qpfreq.QuadPart);
<a name="l00121"></a>00121 <span class="preprocessor">#elif __linux__</span>
<a name="l00122"></a>00122 <span class="preprocessor"></span> value = static_cast<long long>(sec*1E9);
<a name="l00123"></a>00123 <span class="preprocessor">#else </span><span class="comment">/* generic Unix */</span>
<a name="l00124"></a>00124 value = static_cast<long long>(sec*1E6);
<a name="l00125"></a>00125 <span class="preprocessor">#endif </span><span class="comment">/* (choice of OS) */</span>
<a name="l00126"></a>00126 }
<a name="l00127"></a>00127
<a name="l00128"></a><a class="code" href="a00210.html#09dde78a4100800c11bb883d6204b586">00128</a> <span class="keyword">inline</span> <a class="code" href="a00211.html">tick_count::interval_t</a> <a class="code" href="a00210.html#09dde78a4100800c11bb883d6204b586">operator-</a>( <span class="keyword">const</span> <a class="code" href="a00210.html">tick_count</a>& t1, <span class="keyword">const</span> <a class="code" href="a00210.html">tick_count</a>& t0 ) {
<a name="l00129"></a>00129 <span class="keywordflow">return</span> <a class="code" href="a00211.html">tick_count::interval_t</a>( t1.<a class="code" href="a00210.html#1ba05ad46dc08bc1bf34bd6cc94e36ec">my_count</a>-t0.<a class="code" href="a00210.html#1ba05ad46dc08bc1bf34bd6cc94e36ec">my_count</a> );
<a name="l00130"></a>00130 }
<a name="l00131"></a>00131
<a name="l00132"></a><a class="code" href="a00211.html#d5d8429c0bc59cf6131b2abc7929fa59">00132</a> <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="a00211.html#d5d8429c0bc59cf6131b2abc7929fa59">tick_count::interval_t::seconds</a>()<span class="keyword"> const </span>{
<a name="l00133"></a>00133 <span class="preprocessor">#if _WIN32||_WIN64</span>
<a name="l00134"></a>00134 <span class="preprocessor"></span> LARGE_INTEGER qpfreq;
<a name="l00135"></a>00135 QueryPerformanceFrequency(&qpfreq);
<a name="l00136"></a>00136 <span class="keywordflow">return</span> value/(double)qpfreq.QuadPart;
<a name="l00137"></a>00137 #elif __linux__
<a name="l00138"></a>00138 <span class="keywordflow">return</span> value*1E-9;
<a name="l00139"></a>00139 #<span class="keywordflow">else</span> <span class="comment">/* generic Unix */</span>
<a name="l00140"></a>00140 <span class="keywordflow">return</span> value*1E-6;
<a name="l00141"></a>00141 #endif <span class="comment">/* (choice of OS) */</span>
<a name="l00142"></a>00142 }
<a name="l00143"></a>00143
<a name="l00144"></a>00144 } <span class="comment">// namespace tbb</span>
<a name="l00145"></a>00145
<a name="l00146"></a>00146 <span class="preprocessor">#endif </span><span class="comment">/* __TBB_tick_count_H */</span>
<a name="l00147"></a>00147
</pre></div><hr>
<p></p>
Copyright © 2005-2010 Intel Corporation. All Rights Reserved.
<p></p>
Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are
registered trademarks or trademarks of Intel Corporation or its
subsidiaries in the United States and other countries.
<p></p>
* Other names and brands may be claimed as the property of others.
|