<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>console.timeEnd &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/console-timeend/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Firebug&#8217;s console.time() accuracy</title>
		<link>/2010/02/02/firebugs-console-time-accuracy/</link>
		<comments>/2010/02/02/firebugs-console-time-accuracy/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 14:01:16 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[console.time]]></category>
		<category><![CDATA[console.timeEnd]]></category>
		<category><![CDATA[firebug]]></category>

		<guid isPermaLink="false">/?p=1033</guid>
		<description><![CDATA[Firebug’s console.time() As I wrote in my previous post Firebug is giving the ability to test performance of any chunk of JavaScript code with its console.time() method. One of the most discussed topics about performance and one of the most recently examples given in the web is the way to instanciate a new empty array &#8230; <a href="/2010/02/02/firebugs-console-time-accuracy/" class="more-link">Continue reading <span class="screen-reader-text">Firebug&#8217;s console.time() accuracy</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/02/03/firebugs-console-profile-vs-console-time/" rel="bookmark" title="Firebug&#8217;s console.profile vs console.time">Firebug&#8217;s console.profile vs console.time </a></li>
<li><a href="/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/" rel="bookmark" title="Profiling JavaScript with Firebug. console.profile() &#038; console.time()!">Profiling JavaScript with Firebug. console.profile() &#038; console.time()! </a></li>
<li><a href="/2010/06/19/speed-up-the-jquery-code-selectors-cache/" rel="bookmark" title="Speed Up the jQuery Code: Selectors&#8217; Cache">Speed Up the jQuery Code: Selectors&#8217; Cache </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Firebug’s console.time()</h2>
<p>As I wrote in my previous <a href="/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/" target="_self">post</a> Firebug is giving the ability to test performance of any chunk of JavaScript code with its console.time() method. One of the most discussed topics about performance and one of the most recently examples given in the web is the way to instanciate a new empty array in JavaScript.</p>
<blockquote>
<pre>new Array() vs. []</pre>
</blockquote>
<p>Which one is faster? This is the question we’ve seen so many times in the web. I decided to check it with the console.time() method. For my experiment I made 100000 new arrays both way:</p>
<blockquote>
<pre>var arr = new Array();</pre>
</blockquote>
<p>and</p>
<blockquote>
<pre>var arr = [];</pre>
</blockquote>
<p>Thus the sample code of the first experiment is:</p>
<blockquote>
<pre>&lt;html&gt;
 &lt;body&gt;
  &lt;script&gt;
   console.time('profile 1');
   for ( var i=0; i &lt; 100000; i++) {
      var arr = new Array();
   }
   console.timeEnd('profile 1');
  &lt;/script&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre>
</blockquote>
<p>and the results are 12 ms. OK, so far so good. Now I’d like to test the same construction with the other way to make new array instance:</p>
<blockquote>
<pre>&lt;html&gt;
 &lt;body&gt;
  &lt;script&gt;
   console.time('profile 2');
   for ( var i=0; i &lt; 100000; i++) {
      var arr = [];}
   console.timeEnd('profile 2');
  &lt;/script&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre>
</blockquote>
<p>And the result is pretty much the same &#8211; 11 ms. That’s why I choose to increase the number of iterations of this loop from 100,000 to 10,000,000 and the second chunk of code using the construction arr = [] is finishing its job for around 3400ms or a little bit more than 3 seconds, while the first one is a little bit faster &#8211; 2450ms or faster with almost a second.</p>
<h2>What if we merge both chunks?</h2>
<p>I decided to concatenate the code in something like:</p>
<blockquote>
<pre>&lt;html&gt;
 &lt;body&gt;
  &lt;script&gt;
  console.time('profile 1');
   for ( var i=0; i &lt; 100000; i++) {
    var arr = new Array();
   }
  console.timeEnd('profile 1');
  console.time('profile 2');
   for ( var i=0; i &lt; 100000; i++) {
    var arr = [];
   }
  console.timeEnd('profile 2');
  &lt;/script&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre>
</blockquote>
<p><em>results</em>:<a href="/wp-content/uploads/2010/02/Firebug-profile-result.png"><img class="aligncenter size-full wp-image-1034" title="Firebug-profile-result" src="/wp-content/uploads/2010/02/Firebug-profile-result.png" alt="" width="324" height="140" srcset="/wp-content/uploads/2010/02/Firebug-profile-result.png 324w, /wp-content/uploads/2010/02/Firebug-profile-result-300x129.png 300w" sizes="(max-width: 324px) 100vw, 324px" /></a></p>
<p>and yet again the same results as if they were separated tests, which of course seems to be pretty natural.</p>
<h2>Use console.time()!</h2>
<p>That’s the way to get clear example of how fast your code is. Actually this is not a pure sense profile, where you can get minimum and maximum performance times but it gives pretty accurate values.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/02/03/firebugs-console-profile-vs-console-time/" rel="bookmark" title="Firebug&#8217;s console.profile vs console.time">Firebug&#8217;s console.profile vs console.time </a></li>
<li><a href="/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/" rel="bookmark" title="Profiling JavaScript with Firebug. console.profile() &#038; console.time()!">Profiling JavaScript with Firebug. console.profile() &#038; console.time()! </a></li>
<li><a href="/2010/06/19/speed-up-the-jquery-code-selectors-cache/" rel="bookmark" title="Speed Up the jQuery Code: Selectors&#8217; Cache">Speed Up the jQuery Code: Selectors&#8217; Cache </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/02/02/firebugs-console-time-accuracy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
