<?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="https://undocumentedmatlab.com/articles/tic-toc-undocumented-option/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/tic-toc-undocumented-option?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tic-toc-undocumented-option</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Mon, 15 Dec 2014 07:44:19 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-341355</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Mon, 15 Dec 2014 07:44:19 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-341355</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-341337&quot;&gt;Peto&lt;/a&gt;.

@Peto - this is not the right forum for such questions. Try the &lt;a href=&quot;http://www.mathworks.com/matlabcentral/answers/&quot; rel=&quot;nofollow&quot;&gt;Answers&lt;/a&gt; forum.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-341337">Peto</a>.</p>
<p>@Peto &#8211; this is not the right forum for such questions. Try the <a href="http://www.mathworks.com/matlabcentral/answers/" rel="nofollow">Answers</a> forum.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Peto		</title>
		<link>https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-341337</link>

		<dc:creator><![CDATA[Peto]]></dc:creator>
		<pubDate>Mon, 15 Dec 2014 04:39:24 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-341337</guid>

					<description><![CDATA[Can you help me!!!
I want use &quot;tic/toc&quot; or &quot;etime clock&quot; for this code but I don&#039;t know how I make exactly.

[very long code snip...]

 I will appreciate if you help me. 
thank before!]]></description>
			<content:encoded><![CDATA[<p>Can you help me!!!<br />
I want use &#8220;tic/toc&#8221; or &#8220;etime clock&#8221; for this code but I don&#8217;t know how I make exactly.</p>
<p>[very long code snip&#8230;]</p>
<p> I will appreciate if you help me.<br />
thank before!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tobias Schäfer		</title>
		<link>https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-113482</link>

		<dc:creator><![CDATA[Tobias Schäfer]]></dc:creator>
		<pubDate>Mon, 08 Oct 2012 09:45:41 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-113482</guid>

					<description><![CDATA[This might also be used to get the time when the computer was started:
&lt;pre lang=&quot;matlab&quot;&gt;tStart = now - toc(uint64(0))/(60*60*24);
fprintf(1,[&#039;This computer was started at &#039;, datestr(tStart), &#039;.\n&#039;]);
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>This might also be used to get the time when the computer was started:</p>
<pre lang="matlab">tStart = now - toc(uint64(0))/(60*60*24);
fprintf(1,['This computer was started at ', datestr(tStart), '.\n']);
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tobias Schäfer		</title>
		<link>https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-113478</link>

		<dc:creator><![CDATA[Tobias Schäfer]]></dc:creator>
		<pubDate>Mon, 08 Oct 2012 09:16:15 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=310#comment-113478</guid>

					<description><![CDATA[It is the value of a counter operating incrementing with the clock speed of the computer. This line returns the speed of Your machine in Hz:
&lt;pre lang=&quot;matlab&quot;&gt;
&gt;&gt; clk = 1e12 /( toc(uint64(0)) - toc(uint64(1e12)) )
clk =
  2.9925e+009
&lt;/pre&gt;
Press [Windows Key]+[Pause] to check. (Tested on Microsoft Windows XP)]]></description>
			<content:encoded><![CDATA[<p>It is the value of a counter operating incrementing with the clock speed of the computer. This line returns the speed of Your machine in Hz:</p>
<pre lang="matlab">
>> clk = 1e12 /( toc(uint64(0)) - toc(uint64(1e12)) )
clk =
  2.9925e+009
</pre>
<p>Press [Windows Key]+[Pause] to check. (Tested on Microsoft Windows XP)</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Donn Shull		</title>
		<link>https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-55459</link>

		<dc:creator><![CDATA[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><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-55409&quot;&gt;Helge&lt;/a&gt;.

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>In reply to <a href="https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-55409">Helge</a>.</p>
<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>https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-55409</link>

		<dc:creator><![CDATA[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><![CDATA[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:
&#062;&#062; 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>
<pre lang='matlab'>>> tic, for n=1:2^16, k=uint64(n); end; toc</pre>
<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>https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-17041</link>

		<dc:creator><![CDATA[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><![CDATA[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>
<pre lang="matlab">
for i = 1:2:10;
   t0 = double(tic);
   pause(i); 
   t1 = double(tic); 
   dt = t1-t0; 
   per_sec = dt./i; 
   fprintf('dt = %g   per_sec = %g\n', dt, per_sec); 
end
</pre>
<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>
<pre lang="matlab">
ghz = 3.0; uptime = round(double(tic) ./ (ghz * 10^9 * 60))
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Cris		</title>
		<link>https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-2954</link>

		<dc:creator><![CDATA[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><![CDATA[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. 🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: shabby		</title>
		<link>https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-1149</link>

		<dc:creator><![CDATA[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><![CDATA[tic appears to return the number of microseconds since the epoch, at least on my r2007b install on 64 bit linux:

&#062;&#062; [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>https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-952</link>

		<dc:creator><![CDATA[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><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-870&quot;&gt;Alessandro Giusti&lt;/a&gt;.

It is not the number of microseconds on Windows. It has a higher resolution than that.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/tic-toc-undocumented-option#comment-870">Alessandro Giusti</a>.</p>
<p>It is not the number of microseconds on Windows. It has a higher resolution than that.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
