<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: tic / toc &#8211; undocumented option</title> <atom:link href="http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/feed/" rel="self" type="application/rss+xml" /><link>http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/</link> <description>Charting Matlab's unsupported hidden underbelly</description> <lastBuildDate>Thu, 09 Feb 2012 09:23:08 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.1</generator> <item><title>By: Donn Shull</title><link>http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/#comment-55459</link> <dc:creator>Donn Shull</dc:creator> <pubDate>Wed, 31 Aug 2011 18:16:34 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-55459</guid> <description>This won&#039;t shed any new light on tic and toc but I noted in my post on UDD properties that despite having a large array of data types available for a UDD property unsigned integer types were conspicuously absent.</description> <content:encoded><![CDATA[<p>This won&#8217;t shed any new light on tic and toc but I noted in my post on UDD properties that despite having a large array of data types available for a UDD property unsigned integer types were conspicuously absent.</p> ]]></content:encoded> </item> <item><title>By: Helge</title><link>http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/#comment-55409</link> <dc:creator>Helge</dc:creator> <pubDate>Wed, 31 Aug 2011 03:14:56 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-55409</guid> <description>Version compatibility issue(1):Maybe R11 had tic/toc with options (as reported above), I don&#039;t remember. However, R13 does NOT.
So take care if you must guarantee downward compatibility.Version compatibility issue(2):@Alessandro Giusti:
&gt;&gt; uint64(1)+uint64(2)
??? Undefined function or method ‘plus’ for input arguments of type ‘uint64′.
Why?!?Response: help text says: UINT64 is primarily meant to store integer values, and math operations are
NOT defined since they are ambiguous on the boundary of the set (e.g., wrap or truncate there)
UINT32 has (had?) less but essentially similar restrictions, for good reasons.I recognized some inconsistencies between UINT8/16/32/64 regarding the allowed basic math operations
(plus, times). Math support has been improved in versions after R13 but seems still kind of crappy and
--my personal opinion-- even more inconsistent than in R13. Depending on the Matlab version, stuff like
uint32(32)+double(rand) can yield errors or uint32(round(32+rand)), i.e., one can neither rely on errors
nor expect an implicit type conversion to double as in C/C++Frankly, I dont care any longer whether this has changed in new releases -- I simply avoid uint classes
completely except for raw binary file IO or to check input arguments, e.g., using isequal(x,uint16(x)).And regarding the use of uint64 as a counter/hashcode/handle: just try
&lt;pre lang=&#039;matlab&#039;&gt;&gt;&gt; tic, for n=1:2^16, k=uint64(n); end; toc&lt;/pre&gt;
and extrapolate the number of days required until the loop would stop for n=1:2^64.I guess that toc apparently returns UINT64 not because 64 bit precision were technically necessary
or would simplify follow-up operations in Matlab, but rather because UINT64 is what Java or OS library
functions natively return to Matlab, and because Matlab&#039;s tic/toc do not want to waste any time for
type conversion and out-of-range checking/mapping. This leads me to the conclusion that tic/toc should
be potentially more precise than t0=now; ... dt=now-t0; because NOW definitely requires some algorithmic
overhead.Can anybody (in)validate these conclusions?Cheers,  H;</description> <content:encoded><![CDATA[<p>Version compatibility issue(1):</p><p>Maybe R11 had tic/toc with options (as reported above), I don&#8217;t remember. However, R13 does NOT.<br
/> So take care if you must guarantee downward compatibility.</p><p>Version compatibility issue(2):</p><p>@Alessandro Giusti:<br
/> &gt;&gt; uint64(1)+uint64(2)<br
/> ??? Undefined function or method ‘plus’ for input arguments of type ‘uint64′.<br
/> Why?!?</p><p>Response: help text says: UINT64 is primarily meant to store integer values, and math operations are<br
/> NOT defined since they are ambiguous on the boundary of the set (e.g., wrap or truncate there)<br
/> UINT32 has (had?) less but essentially similar restrictions, for good reasons.</p><p>I recognized some inconsistencies between UINT8/16/32/64 regarding the allowed basic math operations<br
/> (plus, times). Math support has been improved in versions after R13 but seems still kind of crappy and<br
/> &#8211;my personal opinion&#8211; even more inconsistent than in R13. Depending on the Matlab version, stuff like<br
/> uint32(32)+double(rand) can yield errors or uint32(round(32+rand)), i.e., one can neither rely on errors<br
/> nor expect an implicit type conversion to double as in C/C++</p><p>Frankly, I dont care any longer whether this has changed in new releases &#8212; I simply avoid uint classes<br
/> completely except for raw binary file IO or to check input arguments, e.g., using isequal(x,uint16(x)).</p><p>And regarding the use of uint64 as a counter/hashcode/handle: just try</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">tic</span>, <span style="color: #0000FF;">for</span> n=<span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">2</span>^<span style="color: #33f;">16</span>, k=uint64<span style="color: #080;">&#40;</span>n<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">end</span>; <span style="color: #0000FF;">toc</span></pre></div></div><p>and extrapolate the number of days required until the loop would stop for n=1:2^64.</p><p>I guess that toc apparently returns UINT64 not because 64 bit precision were technically necessary<br
/> or would simplify follow-up operations in Matlab, but rather because UINT64 is what Java or OS library<br
/> functions natively return to Matlab, and because Matlab&#8217;s tic/toc do not want to waste any time for<br
/> type conversion and out-of-range checking/mapping. This leads me to the conclusion that tic/toc should<br
/> be potentially more precise than t0=now; &#8230; dt=now-t0; because NOW definitely requires some algorithmic<br
/> overhead.</p><p>Can anybody (in)validate these conclusions?</p><p>Cheers,  H;</p> ]]></content:encoded> </item> <item><title>By: Andrew Janke</title><link>http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/#comment-17041</link> <dc:creator>Andrew Janke</dc:creator> <pubDate>Tue, 07 Sep 2010 21:05:14 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-17041</guid> <description>Looks system dependent. On R2009b, R2010a, and R2010b on Windows, I think the tic() unit is the number of CPU clock cycles since the computer&#039;s last boot time. (Not active CPU time, just time counted in the CPU&#039;s clock period.) YMMV, of course. Petter&#039;s tic speed number looks different.&lt;pre lang=&quot;matlab&quot;&gt;
for i = 1:2:10;
t0 = double(tic);
pause(i);
t1 = double(tic);
dt = t1-t0;
per_sec = dt./i;
fprintf(&#039;dt = %g   per_sec = %g\n&#039;, dt, per_sec);
end
&lt;/pre&gt;That results in about 2.84e+009, 3.0e+009 and 3.15e+009 &quot;tic units&quot; per second on the 2.83, 3.0 and 3.16 GHz Windows XP and Server 2003 machines I tested it on.Plug in your machine&#039;s clock speed and you get the uptime.&lt;pre lang=&quot;matlab&quot;&gt;
ghz = 3.0; uptime = round(double(tic) ./ (ghz * 10^9 * 60))
&lt;/pre&gt;</description> <content:encoded><![CDATA[<p>Looks system dependent. On R2009b, R2010a, and R2010b on Windows, I think the tic() unit is the number of CPU clock cycles since the computer&#8217;s last boot time. (Not active CPU time, just time counted in the CPU&#8217;s clock period.) YMMV, of course. Petter&#8217;s tic speed number looks different.</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">for</span> <span style="color: #0000FF;"><span style="color: #33f;">i</span></span> = <span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">2</span><span style="color: #F0F;">:</span><span style="color: #33f;">10</span>;
   t0 = <span style="color: #0000FF;">double</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">tic</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">pause</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;"><span style="color: #33f;">i</span></span><span style="color: #080;">&#41;</span>; 
   t1 = <span style="color: #0000FF;">double</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">tic</span><span style="color: #080;">&#41;</span>; 
   dt = t1-t0; 
   per_sec = dt./<span style="color: #0000FF;"><span style="color: #33f;">i</span></span>; 
   <span style="color: #0000FF;">fprintf</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'dt = %g   per_sec = %g\n'</span>, dt, per_sec<span style="color: #080;">&#41;</span>; 
<span style="color: #0000FF;">end</span></pre></div></div><p>That results in about 2.84e+009, 3.0e+009 and 3.15e+009 &#8220;tic units&#8221; per second on the 2.83, 3.0 and 3.16 GHz Windows XP and Server 2003 machines I tested it on.</p><p>Plug in your machine&#8217;s clock speed and you get the uptime.</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">ghz = <span style="color: #33f;">3.0</span>; uptime = <span style="color: #0000FF;">round</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">double</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">tic</span><span style="color: #080;">&#41;</span> ./ <span style="color: #080;">&#40;</span>ghz * <span style="color: #33f;">10</span>^<span style="color: #33f;">9</span> * <span style="color: #33f;">60</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span></pre></div></div>]]></content:encoded> </item> <item><title>By: Cris</title><link>http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/#comment-2954</link> <dc:creator>Cris</dc:creator> <pubDate>Mon, 28 Sep 2009 09:14:34 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-2954</guid> <description>TIC/TOC has had this option for a long time. I seem to remember it in the MATLAB 5.3 days, but I might be wrong.TIC sets a local persistent variable to the current time. TOC returns the difference between that time and the current time. The value T=TIC just returns the current time, without resetting the local variable. TOC(T) then returns the difference between T and the current time. If T is larger than the current time, it uses the local variable. That is, it ignores its input. How the &quot;current time&quot; is defined could depend on the system, though. I wouldn&#039;t count on it being the time since the computer last rebooted.Oh, I should have checked earlier. I&#039;m just now looking at HELP TIC and HELP TOC. This feature is documented in R2009a. :)</description> <content:encoded><![CDATA[<p>TIC/TOC has had this option for a long time. I seem to remember it in the MATLAB 5.3 days, but I might be wrong.</p><p>TIC sets a local persistent variable to the current time. TOC returns the difference between that time and the current time. The value T=TIC just returns the current time, without resetting the local variable. TOC(T) then returns the difference between T and the current time. If T is larger than the current time, it uses the local variable. That is, it ignores its input. How the &#8220;current time&#8221; is defined could depend on the system, though. I wouldn&#8217;t count on it being the time since the computer last rebooted.</p><p>Oh, I should have checked earlier. I&#8217;m just now looking at HELP TIC and HELP TOC. This feature is documented in R2009a. <img
src='http://undocumentedmatlab.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> </item> <item><title>By: shabby</title><link>http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/#comment-1149</link> <dc:creator>shabby</dc:creator> <pubDate>Tue, 02 Jun 2009 17:45:50 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-1149</guid> <description>tic appears to return the number of microseconds since the epoch, at least on my r2007b install on 64 bit linux:&gt;&gt; [a,retv_pre] = system(&#039;date +&#039;&#039;%s&#039;&#039;&#039;);ticv = tic();[a,retv_post] = system(&#039;date +&#039;&#039;%s&#039;&#039;&#039;);retv_avg = 0.5 * (str2num(retv_pre) + str2num(retv_post));retv_avg - (double(ticv) / 1e6)ans =-0.5501</description> <content:encoded><![CDATA[<p>tic appears to return the number of microseconds since the epoch, at least on my r2007b install on 64 bit linux:</p><p>&gt;&gt; [a,retv_pre] = system(&#8216;date +&#8221;%s&#8221;&#8217;);ticv = tic();[a,retv_post] = system(&#8216;date +&#8221;%s&#8221;&#8217;);retv_avg = 0.5 * (str2num(retv_pre) + str2num(retv_post));retv_avg &#8211; (double(ticv) / 1e6)</p><p>ans =</p><p> -0.5501</p> ]]></content:encoded> </item> <item><title>By: Petter</title><link>http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/#comment-952</link> <dc:creator>Petter</dc:creator> <pubDate>Tue, 26 May 2009 06:41:09 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-952</guid> <description>It is not the number of microseconds on Windows. It has a higher resolution than that.</description> <content:encoded><![CDATA[<p>It is not the number of microseconds on Windows. It has a higher resolution than that.</p> ]]></content:encoded> </item> <item><title>By: Alessandro Giusti</title><link>http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/#comment-870</link> <dc:creator>Alessandro Giusti</dc:creator> <pubDate>Fri, 22 May 2009 20:03:51 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-870</guid> <description>I think that the uint64 number returned by tic is the number of microseconds after the system started.   It is also the most straightforward way to implement such tic/toc mechanism.The usual behavior of other functions, instead, made me initially think of the value being some sort of handle to internal data, which is probably not. :-)This is confirmed by a couple of tests (at least under linux):&gt;&gt; a=tic; pause(1); b=tic;
&gt;&gt; disp(double(b)-double(a))
1000624&gt;&gt; a=tic; pause(2); b=tic;
&gt;&gt; disp(double(b)-double(a))
2000627... and also:
&gt;&gt; a=tic; pause(1); toc(uint64(double(a)+1))
Elapsed time is 1.000410 seconds.A partly unrelated note:&gt;&gt; uint64(1)+uint64(2)
??? Undefined function or method &#039;plus&#039; for input arguments of type &#039;uint64&#039;.Why?!?</description> <content:encoded><![CDATA[<p>I think that the uint64 number returned by tic is the number of microseconds after the system started.   It is also the most straightforward way to implement such tic/toc mechanism.</p><p>The usual behavior of other functions, instead, made me initially think of the value being some sort of handle to internal data, which is probably not. <img
src='http://undocumentedmatlab.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p><p>This is confirmed by a couple of tests (at least under linux):</p><p>&gt;&gt; a=tic; pause(1); b=tic;<br
/> &gt;&gt; disp(double(b)-double(a))<br
/> 1000624</p><p>&gt;&gt; a=tic; pause(2); b=tic;<br
/> &gt;&gt; disp(double(b)-double(a))<br
/> 2000627</p><p>&#8230; and also:<br
/> &gt;&gt; a=tic; pause(1); toc(uint64(double(a)+1))<br
/> Elapsed time is 1.000410 seconds.</p><p>A partly unrelated note:</p><p>&gt;&gt; uint64(1)+uint64(2)<br
/> ??? Undefined function or method &#8216;plus&#8217; for input arguments of type &#8216;uint64&#8242;.</p><p>Why?!?</p> ]]></content:encoded> </item> <item><title>By: Petter</title><link>http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/#comment-864</link> <dc:creator>Petter</dc:creator> <pubDate>Fri, 22 May 2009 16:42:42 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-864</guid> <description>The value returned by tic is not a handle. It is just a counter with some native time step.On my computer, one tic is 6.9836e-008 seconds, according to my measurements.  This internal counter starts at 0 when the computer starts.</description> <content:encoded><![CDATA[<p>The value returned by tic is not a handle. It is just a counter with some native time step.</p><p>On my computer, one tic is 6.9836e-008 seconds, according to my measurements.  This internal counter starts at 0 when the computer starts.</p> ]]></content:encoded> </item> <item><title>By: Petter</title><link>http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/#comment-863</link> <dc:creator>Petter</dc:creator> <pubDate>Fri, 22 May 2009 16:35:21 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-863</guid> <description>It is equal to the uptime of my computer.</description> <content:encoded><![CDATA[<p>It is equal to the uptime of my computer.</p> ]]></content:encoded> </item> <item><title>By: Yair Altman</title><link>http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/#comment-862</link> <dc:creator>Yair Altman</dc:creator> <pubDate>Fri, 22 May 2009 14:58:03 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-862</guid> <description>You must be right Jason - this also correlates with the number I posted above. Good catch!</description> <content:encoded><![CDATA[<p>You must be right Jason &#8211; this also correlates with the number I posted above. Good catch!</p> ]]></content:encoded> </item> </channel> </rss>

<!-- W3 Total Cache: Minify debug info:
Engine:             disk: basic
Theme:              b7666
Template:           single
-->
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: undocumentedmatlab.com @ 2012-02-09 05:10:05 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/tic-toc-undocumented-option/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      0.745s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1328789405; expires=Fri, 08-Feb-2013 12:10:05 GMT; path=/
Link:               <http://undocumentedmatlab.com/?p=310>; rel=shortlink
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Thu, 09 Feb 2012 12:10:05 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Thu, 09 Feb 2012 13:10:05 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               5d7a9fb5f26dffe57f24485b33df8391
Content-Encoding:   gzip
-->
