<?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>firebug &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/firebug/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>JavaScript Performance: for vs. while</title>
		<link>/2012/01/24/javascript-performance-for-vs-while/</link>
		<comments>/2012/01/24/javascript-performance-for-vs-while/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 14:20:05 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Control flow]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[Increment]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[software/hardware]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[While loop]]></category>

		<guid isPermaLink="false">/?p=2635</guid>
		<description><![CDATA[JavaScript Loops If you have read some preformance tests on JavaScript loops, you may have heard that &#8220;while&#8221; is faster than &#8220;for&#8221;. However the question is how faster is &#8220;while&#8221;? Here are some results, but first let&#8217;s take a look on the JavaScript code. The for experiment console.time('for'); for (var i = 0; i < &#8230; <a href="/2012/01/24/javascript-performance-for-vs-while/" class="more-link">Continue reading <span class="screen-reader-text">JavaScript Performance: for vs. while</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </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/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/06/02/detecting-pressed-key-with-e-which-in-javascript/" rel="bookmark" title="Detecting Pressed Key with e.which in JavaScript">Detecting Pressed Key with e.which in JavaScript </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>JavaScript Loops</h2>
<p>If you have read some preformance tests on JavaScript loops, you may have heard that &#8220;while&#8221; is faster than &#8220;for&#8221;. However the question is how faster is &#8220;while&#8221;? Here are some results, but first let&#8217;s take a look on the JavaScript code. </p>
<h4>The <strong>for</strong> experiment</h4>
<pre lang="javascript">
console.time('for');
for (var i = 0; i < 10000000; i++) {
	i / 2;
}
console.timeEnd('for');
</pre>
<h4>The <strong>while</strong> experiment</h4>
<pre lang="javascript">
console.time('while');
var i = 0;
while (i++ < 10000000) {
	i / 2;
}
console.timeEnd('while');
</pre>
<p>Note - these tests are performed and measured with Firebug on Firefox.</p>
<h2>Results</h2>
<p>It's a fact, that you'll get different results as many times as you run this snippet. It depends also on the enviroment and software/hardware specs. That is why I performed them 10 times and then I took the average value. Here are the values of my performance tests. Note that both <strong>for</strong> and <strong>while</strong> perform 10,000,000 iterations.</p>
<p><iframe width='576' height='263' frameborder='0' src='https://docs.google.com/spreadsheet/pub?hl=en_US&#038;hl=en_US&#038;key=0Avxdu4aY4-UGdDktZEJHYUh5RWFLd1prOG52dDdTdUE&#038;single=true&#038;gid=0&#038;output=html&#038;widget=true'></iframe></p>
<h2>And the Winner Is</h2>
<p><strong>While</strong> is the winner with an average result of 83.5 milliseconds, while "for" result is 88 average milliseconds.</p>
<p>As the diagram bellow shows, <strong>the while loop is slightly faster</strong>. However we should be aware that these performance gains are significant for large number of iterations!</p>
<figure id="attachment_2668" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/01/chart_1-1.png"><img src="/wp-content/uploads/2012/01/chart_1-1.png" alt="JavaScript Performance: for vs. while" title="JavaScript Performance: for vs. while" width="600" height="371" class="size-full wp-image-2668" srcset="/wp-content/uploads/2012/01/chart_1-1.png 600w, /wp-content/uploads/2012/01/chart_1-1-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text">JavaScript Performance: for vs. while</figcaption></figure>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </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/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/06/02/detecting-pressed-key-with-e-which-in-javascript/" rel="bookmark" title="Detecting Pressed Key with e.which in JavaScript">Detecting Pressed Key with e.which in JavaScript </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/01/24/javascript-performance-for-vs-while/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Friday Algorithms: JavaScript Merge Sort</title>
		<link>/2010/07/02/friday-algorithms-javascript-merge-sort/</link>
		<comments>/2010/07/02/friday-algorithms-javascript-merge-sort/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 10:28:16 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[algorithms]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Merge sort]]></category>
		<category><![CDATA[Sorting algorithms]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">/?p=1746</guid>
		<description><![CDATA[Merge Sort This week I&#8217;m going to cover one very popular sorting algorithm &#8211; the merge sort. It&#8217;s very intuitive and simple as it&#8217;s described in Wikipedia: If the list is of length 0 or 1, then it is already sorted. Otherwise: Divide the unsorted list into two sublists of about half the size. Sort &#8230; <a href="/2010/07/02/friday-algorithms-javascript-merge-sort/" class="more-link">Continue reading <span class="screen-reader-text">Friday Algorithms: JavaScript Merge Sort</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/07/09/friday-algorithms-javascript-bubble-sort/" rel="bookmark" title="Friday Algorithms: JavaScript Bubble Sort">Friday Algorithms: JavaScript Bubble Sort </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>
<li><a href="/2012/03/05/computer-algorithms-merge-sort/" rel="bookmark" title="Computer Algorithms: Merge Sort">Computer Algorithms: Merge Sort </a></li>
<li><a href="/2010/01/21/array-merge-in-javascript/" rel="bookmark" title="Array merge in JavaScript">Array merge in JavaScript </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Merge Sort</h2>
<p>This week I&#8217;m going to cover one very popular sorting algorithm &#8211; the merge sort. It&#8217;s very intuitive and simple as it&#8217;s described in <a title="Merge Sort" href="http://en.wikipedia.org/wiki/Merge_sort" target="_blank">Wikipedia</a>:</p>
<ul>
<li>If the list is of length 0 or 1, then it is already sorted.  Otherwise:</li>
<li>Divide the unsorted list into two sublists of about half the size.</li>
<li>Sort each sublist recursively by re-applying merge sort.</li>
<li>Merge the two sublists back into one sorted list.</li>
</ul>
<h2>Here&#8217;s the Source</h2>
<p><em>(JavaScript)</em></p>
<pre lang="javascript">
var a = [34, 203, 3, 746, 200, 984, 198, 764, 9];

function mergeSort(arr)
{
    if (arr.length < 2)
        return arr;

    var middle = parseInt(arr.length / 2);
    var left   = arr.slice(0, middle);
    var right  = arr.slice(middle, arr.length);

    return merge(mergeSort(left), mergeSort(right));
}

function merge(left, right)
{
    var result = [];

    while (left.length &#038;&#038; right.length) {
        if (left[0] <= right[0]) {
            result.push(left.shift());
        } else {
            result.push(right.shift());
        }
    }

    while (left.length)
        result.push(left.shift());

    while (right.length)
        result.push(right.shift());

    return result;
}

console.log(mergeSort(a));
</pre>
<p>It's interesting to see what happens in the Firebug's console:</p>
<pre lang="javascript">
[34, 203, 3, 746] [200, 984, 198, 764, 9]

[34, 203] [3, 746]

[34] [203]

[3] [746]

[200, 984] [198, 764, 9]

[200] [984]

[198] [764, 9]

[764] [9]

[3, 9, 34, 198, 200, 203, 746, 764, 984]
</pre>
<p>Actually the tricky part in this algorithm is the merge function - it does all the work. </p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/07/09/friday-algorithms-javascript-bubble-sort/" rel="bookmark" title="Friday Algorithms: JavaScript Bubble Sort">Friday Algorithms: JavaScript Bubble Sort </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>
<li><a href="/2012/03/05/computer-algorithms-merge-sort/" rel="bookmark" title="Computer Algorithms: Merge Sort">Computer Algorithms: Merge Sort </a></li>
<li><a href="/2010/01/21/array-merge-in-javascript/" rel="bookmark" title="Array merge in JavaScript">Array merge in JavaScript </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/07/02/friday-algorithms-javascript-merge-sort/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Modyfing Response Headers with Zend Framework</title>
		<link>/2010/03/24/modyfing-response-headers-with-zend-framework/</link>
		<comments>/2010/03/24/modyfing-response-headers-with-zend-framework/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 18:53:46 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[Human Interest]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Web application frameworks]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">/?p=1383</guid>
		<description><![CDATA[Response Headers You&#8217;ve probably seen that you can track the server response headers with Firebug &#8211; a wonderful extension to Firefox. But have you ever asked yourself how to change a response header with Zend Framework. header() Typically this is done with the built in PHP function header, where you can setup the header the &#8230; <a href="/2010/03/24/modyfing-response-headers-with-zend-framework/" class="more-link">Continue reading <span class="screen-reader-text">Modyfing Response Headers with Zend Framework</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/06/10/json-and-zend-framework-zend_json/" rel="bookmark" title="JSON and Zend Framework? &#8211; Zend_Json">JSON and Zend Framework? &#8211; Zend_Json </a></li>
<li><a href="/2010/05/25/download-files-with-zend-framework/" rel="bookmark" title="Download Files with Zend Framework">Download Files with Zend Framework </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
<li><a href="/2010/01/25/using-zend-framework-validators-zend_validate_db_recordexists/" rel="bookmark" title="Using Zend Framework validators &#8211; Zend_Validate_Db_RecordExists">Using Zend Framework validators &#8211; Zend_Validate_Db_RecordExists </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Response Headers</h2>
<p>You&#8217;ve probably seen that you can track the server response headers with Firebug &#8211; a wonderful extension to Firefox.</p>
<p><a href="/wp-content/uploads/2010/03/Picture-11.png"><img class="aligncenter size-medium wp-image-1384" title="Firebug Response Headers" src="/wp-content/uploads/2010/03/Picture-11-300x86.png" alt="" width="300" height="86" srcset="/wp-content/uploads/2010/03/Picture-11-300x86.png 300w, /wp-content/uploads/2010/03/Picture-11.png 518w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>But have you ever asked yourself how to change a response header with Zend Framework.</p>
<h2>header()</h2>
<p>Typically this is done with the built in PHP function header, where you can setup the header the page must return, but how to make it with Zend Framework?</p>
<p>It&#8217;s pretty simple of course, it&#8217;s Zend Framework in fact. To be more precise I&#8217;ll post a snippet:</p>
<pre lang="php" escaped="true">
$response = $this-&gt;getResponse();
$response-&gt;setHeader('content-type', 'application/x-javascript; charset=utf-8');
$response-&gt;sendResponse();
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/06/10/json-and-zend-framework-zend_json/" rel="bookmark" title="JSON and Zend Framework? &#8211; Zend_Json">JSON and Zend Framework? &#8211; Zend_Json </a></li>
<li><a href="/2010/05/25/download-files-with-zend-framework/" rel="bookmark" title="Download Files with Zend Framework">Download Files with Zend Framework </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
<li><a href="/2010/01/25/using-zend-framework-validators-zend_validate_db_recordexists/" rel="bookmark" title="Using Zend Framework validators &#8211; Zend_Validate_Db_RecordExists">Using Zend Framework validators &#8211; Zend_Validate_Db_RecordExists </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/03/24/modyfing-response-headers-with-zend-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CSS Priority: The Difference Between a.my-class and .my-class</title>
		<link>/2010/03/11/css-priority-the-difference-between-a-my-class-and-my-class/</link>
		<comments>/2010/03/11/css-priority-the-difference-between-a-my-class-and-my-class/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 14:58:28 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[Cascading Style Sheets]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[Google Inc.]]></category>
		<category><![CDATA[Span and div]]></category>
		<category><![CDATA[Web design]]></category>

		<guid isPermaLink="false">/?p=1222</guid>
		<description><![CDATA[Do You Know What&#8217;s an Inefficient CSS Selector? Perhaps! I was curious how can inefficient selectors impact a page performance. To begin with this topic let me say that inefficient selector is referred usually as nested selector: div span div { border:1px solid red; } as you can see here there are three nested tags &#8230; <a href="/2010/03/11/css-priority-the-difference-between-a-my-class-and-my-class/" class="more-link">Continue reading <span class="screen-reader-text">CSS Priority: The Difference Between a.my-class and .my-class</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/02/04/css-effective-selector/" rel="bookmark" title="CSS effective selector">CSS effective selector </a></li>
<li><a href="/2010/01/30/optimizing-css-five-simple-steps/" rel="bookmark" title="Optimizing CSS. Five simple steps!">Optimizing CSS. Five simple steps! </a></li>
<li><a href="/2010/01/18/what-if-your-site-doesnt-use-all-of-the-css-selectors/" rel="bookmark" title="What if your site doesn&#8217;t use all of the CSS selectors?">What if your site doesn&#8217;t use all of the CSS selectors? </a></li>
<li><a href="/2010/02/15/css-selectors-new-look-over-them/" rel="bookmark" title="CSS selectors &#8211; new look over them">CSS selectors &#8211; new look over them </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Do You Know What&#8217;s an Inefficient CSS Selector?</h2>
<p>Perhaps! I was curious how can inefficient selectors impact a page performance. To begin with this topic let me say that inefficient selector is referred usually as nested selector:</p>
<pre lang="css">div span div {
    border:1px solid red;
}
</pre>
<p>as you can see here there are three nested tags I use to reference the innermost div. If you&#8217;re wondering how you&#8217;d know about inefficient selectors &#8211; well there is a plugin for the <a title="Firebug" href="http://getfirebug.com/" target="_blank">Firebug</a> written by a Google team called <a title="Page Speed" href="http://code.google.com/speed/page-speed/" target="_blank">Page Speed</a> explaining which of your selectors are inefficient. See the image below.</p>
<p><a href="/wp-content/uploads/2010/03/css-selectors-inefficient1.png"><img class="aligncenter size-full wp-image-1273" title="css-selectors-inefficient" src="/wp-content/uploads/2010/03/css-selectors-inefficient1.png" alt="CSS Page Speed Inefficient Selectors" width="430" height="113" srcset="/wp-content/uploads/2010/03/css-selectors-inefficient1.png 430w, /wp-content/uploads/2010/03/css-selectors-inefficient1-300x78.png 300w" sizes="(max-width: 430px) 100vw, 430px" /></a></p>
<p>In the <a title="CSS Performance Demo" href="http://www.stoimen.com/projects/css.selectors.performance/" target="_blank">demo</a> page you can find what I was trying to achieve and you can play around with that code to measure by yourself the performance of the different selectors.</p>
<h2>So who&#8217;s faster? Nested, IDs or Classes?</h2>
<p>Actually its pretty though to say. Yet another surprise for me was to notice that the notation:</p>
<pre lang="css">div.my-class {}
</pre>
<p>was a bit slower than the marked as <em>&#8220;inefficient&#8221;</em> by Page Speed:</p>
<pre lang="css">div span div {}
</pre>
<p>Another good thing to mention is that there is a difference between div.my-class and .my-class</p>
<h2>Question&#8217;s answer &#8230;</h2>
<p>In fact <strong>div.my-class</strong> is always with a higher priority than <strong>.my-class</strong> even if you&#8217;ve the following code:</p>
<pre lang="css">div.my-class {
    border:1px solid red;
}

.my-class {
    border:1px solid blue;
}

div span div {
    border:1px solid black;
}
</pre>
<p>And the computed style for Firefox was &#8230;</p>
<p><a href="/wp-content/uploads/2010/03/css-selectors-code.png"><img class="aligncenter size-full wp-image-1274" title="css-selectors-code" src="/wp-content/uploads/2010/03/css-selectors-code.png" alt="CSS Selector Performance Computed Style" width="430" height="170" srcset="/wp-content/uploads/2010/03/css-selectors-code.png 430w, /wp-content/uploads/2010/03/css-selectors-code-300x118.png 300w" sizes="(max-width: 430px) 100vw, 430px" /></a></p>
<p>where &#8220;div span div&#8221; chain matches the same elements as the previous selectors, as you can see:</p>
<p><a href="/wp-content/uploads/2010/03/css-selectors-dom-view.png"><img class="aligncenter size-full wp-image-1275" title="css-selectors-dom-view" src="/wp-content/uploads/2010/03/css-selectors-dom-view.png" alt="CSS Selector DOM View" width="430" height="127" srcset="/wp-content/uploads/2010/03/css-selectors-dom-view.png 430w, /wp-content/uploads/2010/03/css-selectors-dom-view-300x88.png 300w" sizes="(max-width: 430px) 100vw, 430px" /></a></p>
<p>so even that <strong>div.my-class</strong> will be the most important and finally the element will get its red border! It does not depend only on where you put the CSS rules, but also on how they are defined.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/02/04/css-effective-selector/" rel="bookmark" title="CSS effective selector">CSS effective selector </a></li>
<li><a href="/2010/01/30/optimizing-css-five-simple-steps/" rel="bookmark" title="Optimizing CSS. Five simple steps!">Optimizing CSS. Five simple steps! </a></li>
<li><a href="/2010/01/18/what-if-your-site-doesnt-use-all-of-the-css-selectors/" rel="bookmark" title="What if your site doesn&#8217;t use all of the CSS selectors?">What if your site doesn&#8217;t use all of the CSS selectors? </a></li>
<li><a href="/2010/02/15/css-selectors-new-look-over-them/" rel="bookmark" title="CSS selectors &#8211; new look over them">CSS selectors &#8211; new look over them </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/03/11/css-priority-the-difference-between-a-my-class-and-my-class/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to detect a variable existence in JavaScript?</title>
		<link>/2010/02/12/how-to-detect-a-variable-existence-in-javascript/</link>
		<comments>/2010/02/12/how-to-detect-a-variable-existence-in-javascript/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 09:01:09 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Existential quantification]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[IP]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[Logic]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Quantification]]></category>
		<category><![CDATA[Social Issues]]></category>
		<category><![CDATA[Stoyan Stefanov]]></category>
		<category><![CDATA[Universal quantification]]></category>

		<guid isPermaLink="false">/?p=1083</guid>
		<description><![CDATA[Preface After reading one of the latest posts from Stoyan Stefanov&#8217;s blog &#8211; phpied.com I stumbled upon an interesting construction in JavaScript describing how to check an object property existence. I&#8217;m going to cover this case using as an example the console object, which comes with the Firebug enabled, and I think it may be &#8230; <a href="/2010/02/12/how-to-detect-a-variable-existence-in-javascript/" class="more-link">Continue reading <span class="screen-reader-text">How to detect a variable existence in JavaScript?</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<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="/2009/07/27/jquery-debug-plugin/" rel="bookmark" title="jQuery debug plugin">jQuery debug plugin </a></li>
<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="/2009/07/04/jquery-check-for-element-existence-in-the-dom/" rel="bookmark" title="jquery check for element existence in the DOM">jquery check for element existence in the DOM </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Preface</h2>
<p>After reading one of the latest posts from Stoyan Stefanov&#8217;s blog &#8211; <a title="Stoyan Stefanov's blog" href="http://phpied.com/" target="_blank">phpied.com</a> I stumbled upon an interesting construction in JavaScript describing how to check an object property existence. I&#8217;m going to cover this case using as an example the console object, which comes with the Firebug enabled, and I think it may be very useful, just because this object is widely used, but doesn&#8217;t exists over all the browsers, even under Firefox when Firebug is disabled. This construction is known as the IN statement and it looks something like that:</p>
<pre lang="javascript">property in object
</pre>
<p>which I&#8217;m going to cover later in details.</p>
<h2>How you detect a variable existence?</h2>
<p>There are three main ways to detect the existence of a property I see in my practice.</p>
<p>1. The most widely used:</p>
<pre lang="javascript">if ( console ) { ... }</pre>
<p>2. The second and more professional one:</p>
<pre lang="javascript">if ( typeof console != 'undefined' ) { ... }</pre>
<p>3. And finally the third and most unknown:</p>
<pre lang="javascript">if ( console in window ) { ... }</pre>
<p>Of course two of them are wrong! Which one should be changed?</p>
<h2>Is everything working correctly? No!</h2>
<p>Lets see how they are working. First of all I&#8217;m going to test all of them on Firefox 3.6 either with enabled and disabled Firebug, just shouting with old school&#8217;s<strong> alert().</strong></p>
<p>Now the first one using the IN statement:</p>
<pre lang="javascript">if ( console in window )
   alert('object exists!');
else
   alert('object doesn\'t exists!');
</pre>
<p>With Firebug disabled the answer is &#8230; nothing! No alert! That&#8217;s because the syntax is wrong. There&#8217;s an error within the IF statement. We should modify a bit the first row like that:</p>
<pre lang="javascript">if ( 'console' in window )
   alert('object exists!');
else
   alert('object doesn\'t exists!');
</pre>
<p>Now everything&#8217;s OK. With a disabled Firebug the answer is: &#8220;object doesn&#8217;t exists!&#8221;, and after enabling it, normally the &#8220;object exists!&#8221;.</p>
<p>Lets move on the next example:</p>
<pre lang="javascript">if ( console )
   alert('object exists!');
else
   alert('object doesn\'t exists!');
</pre>
<p>With Firebug enabled the answer is as we expect: &#8220;object exists!&#8221;, but after disabling it yet again &#8211; nothing?! Why&#8217;s that? Because the console object doesn&#8217;t exists anymore and the IF statement doesn&#8217;t return true or false, but simply crashes. How to modify the code? Simply by adding a window.console instead of console.</p>
<pre lang="javascript">if ( window.console )
   alert('object exists!');
else
   alert('object doesn\'t exists!');
</pre>
<p>Than the answer is: &#8220;the object doesn&#8217;t exists!&#8221; after what we expected!</p>
<p>The third method is the mostly used, just because it&#8217;s completely clear what&#8217;s the goal of the IF statement:</p>
<pre lang="javascript">if ( typeof console != 'undefined' )
   alert('object exists!');
else
   alert('object doesn\'t exists!');
</pre>
<p>In both disabled and enabled Firebug the answer is as expected!</p>
<p>Now the IN statement may be used if not for the console, but for checking the existence of a property of within an object.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<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="/2009/07/27/jquery-debug-plugin/" rel="bookmark" title="jQuery debug plugin">jQuery debug plugin </a></li>
<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="/2009/07/04/jquery-check-for-element-existence-in-the-dom/" rel="bookmark" title="jquery check for element existence in the DOM">jquery check for element existence in the DOM </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/02/12/how-to-detect-a-variable-existence-in-javascript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CSS effective selector</title>
		<link>/2010/02/04/css-effective-selector/</link>
		<comments>/2010/02/04/css-effective-selector/#respond</comments>
		<pubDate>Thu, 04 Feb 2010 15:27:31 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Cascading Style Sheets]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[Google Inc.]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=1046</guid>
		<description><![CDATA[CSS optimization Recently I posted an article about CSS optimization describing five simple steps you can do to speed up the page load time and the bowser execution time. One of the key features is to use effective selectors, but what exactly that means. Parents and children In CSS, after the name of cascading, there &#8230; <a href="/2010/02/04/css-effective-selector/" class="more-link">Continue reading <span class="screen-reader-text">CSS effective selector</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/03/11/css-priority-the-difference-between-a-my-class-and-my-class/" rel="bookmark" title="CSS Priority: The Difference Between a.my-class and .my-class">CSS Priority: The Difference Between a.my-class and .my-class </a></li>
<li><a href="/2010/01/18/what-if-your-site-doesnt-use-all-of-the-css-selectors/" rel="bookmark" title="What if your site doesn&#8217;t use all of the CSS selectors?">What if your site doesn&#8217;t use all of the CSS selectors? </a></li>
<li><a href="/2010/01/30/optimizing-css-five-simple-steps/" rel="bookmark" title="Optimizing CSS. Five simple steps!">Optimizing CSS. Five simple steps! </a></li>
<li><a href="/2010/02/15/css-selectors-new-look-over-them/" rel="bookmark" title="CSS selectors &#8211; new look over them">CSS selectors &#8211; new look over them </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>CSS optimization</h2>
<p>Recently I <a href="/2010/01/30/optimizing-css-five-simple-steps/" target="_blank">posted</a> an article about CSS optimization describing five simple steps you can do to speed up the page load time and the bowser execution time. One of the key features is to use effective selectors, but what exactly that means.</p>
<h2>Parents and children</h2>
<p>In <a title="css" href="http://en.wikipedia.org/wiki/CSS" target="_blank">CSS</a>, after the name of cascading, there is a very powerful feature of inheritance and you can simply describe a child style by a selector which can be something like that:</p>
<blockquote>
<pre>div table tr td a { color: red; }</pre>
</blockquote>
<p>In reality is very, but very inefficient. Event it is a working example, the browser will find every anchor <strong>&lt;a</strong> tag within the page than check if it&#8217;s child of a <strong>td</strong>, than <strong>tr</strong> and so on until the closing outer most <strong>div</strong> tag.</p>
<p>That&#8217;s why the browser is really hard to find every one of these tags just to apply a simple font color. What the big problem is that once you have thousands of tags in that page the browser starts to use CPU and the application starts to be irresponsive.</p>
<h2>The solution</h2>
<p>Of course there&#8217;s a simple solution, which can be described as transformation from inefficient to efficient selectors. Because the browser can find a tag way faster by a given ID or CLASS you can simply convert the code above with something like:</p>
<blockquote>
<pre>a.my-class { color: red; }</pre>
</blockquote>
<p>and than change a bit the markup with a tags with that specific class name. Which is a bit tricky, but speedups the performance a lot.</p>
<h2>How can I find bad selectors?</h2>
<p>Actually that is the big problem. Once you&#8217;re into the deep of web development the applications are so big, with so many CSS selectors and so many CSS rules that you simply cannot track that any more.</p>
<p>Hopefully there comes some tools that can describe you everything and point you the inefficient selectors. My personal choice is the Google&#8217;s <a title="Page Speed" href="http://code.google.com/intl/en-En/speed/page-speed/" target="_blank">Page Speed</a> plugin, which can be installed to the <a title="Firebug" href="https://addons.mozilla.org/en-US/firefox/addon/1843" target="_blank">Firebug</a> on <a title="Mozilla Firefox" href="http://www.mozilla.com/firefox/" target="_blank">Mozilla Firefox</a>. It can analyze the page and extract a list of inefficient and so called very inefficient selectors that must be fixed!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/03/11/css-priority-the-difference-between-a-my-class-and-my-class/" rel="bookmark" title="CSS Priority: The Difference Between a.my-class and .my-class">CSS Priority: The Difference Between a.my-class and .my-class </a></li>
<li><a href="/2010/01/18/what-if-your-site-doesnt-use-all-of-the-css-selectors/" rel="bookmark" title="What if your site doesn&#8217;t use all of the CSS selectors?">What if your site doesn&#8217;t use all of the CSS selectors? </a></li>
<li><a href="/2010/01/30/optimizing-css-five-simple-steps/" rel="bookmark" title="Optimizing CSS. Five simple steps!">Optimizing CSS. Five simple steps! </a></li>
<li><a href="/2010/02/15/css-selectors-new-look-over-them/" rel="bookmark" title="CSS selectors &#8211; new look over them">CSS selectors &#8211; new look over them </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/02/04/css-effective-selector/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firebug&#8217;s console.profile vs console.time</title>
		<link>/2010/02/03/firebugs-console-profile-vs-console-time/</link>
		<comments>/2010/02/03/firebugs-console-profile-vs-console-time/#respond</comments>
		<pubDate>Wed, 03 Feb 2010 12:59:33 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Anonymous function]]></category>
		<category><![CDATA[Closure]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">/?p=1038</guid>
		<description><![CDATA[Firebug&#8217;s console.time! This post is directly related to the previous post where I explain how to use the Firebug&#8217;s console object and in that case its time method. That is really powerful and gives the opportunity to track the performance of a sample JavaScript chunk of code. What it does not do is to give &#8230; <a href="/2010/02/03/firebugs-console-profile-vs-console-time/" class="more-link">Continue reading <span class="screen-reader-text">Firebug&#8217;s console.profile vs console.time</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<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/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Firebug&#8217;s console.time!</h2>
<p>This post is directly related to the previous <a href="/2010/02/02/firebugs-console-time-accuracy/" target="_self">post</a> where I explain how to use the Firebug&#8217;s console object and in that case its time method. That is really powerful and gives the opportunity to track the performance of a sample JavaScript chunk of code. What it does not do is to give you a more detailed profile of that particular JS code.</p>
<p>That&#8217;s because the console&#8217;s profile method works on functions and if you&#8217;d like to profile a loop it will give you there&#8217;s nothing to be profiled. One workaround to that is to use closures.</p>
<h2>JavaScript closures</h2>
<p>A JavaScript closure is to make an anonymous function and to put the code in it, like so:</p>
<blockquote>
<pre>(function() {
 for (var i = 100000; i--; ) {
  var a = new Array();
 }
})();</pre>
</blockquote>
<h2>Firebug&#8217;s console.profile()</h2>
<p>That code can be than wrapped with both console.profile() and console.profileEnd() in something like:</p>
<blockquote>
<pre>console.profile('my profile');
(function() {
 for ( var i = 100000; i--; ) {
  var a  = new Array();
 }
})();
console.profileEnd('my profile');</pre>
</blockquote>
<p>That will give a more precise measurement like that one shown on the picture bellow:</p>
<p><img class="aligncenter size-full wp-image-1041" title="firebug-profile" src="/wp-content/uploads/2010/02/firebug-profile.png" alt="firebug console.profile" width="430" height="140" srcset="/wp-content/uploads/2010/02/firebug-profile.png 430w, /wp-content/uploads/2010/02/firebug-profile-300x97.png 300w" sizes="(max-width: 430px) 100vw, 430px" /></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<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/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/02/03/firebugs-console-profile-vs-console-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>
		<item>
		<title>Profiling JavaScript with Firebug. console.profile() &#038; console.time()!</title>
		<link>/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/</link>
		<comments>/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/#respond</comments>
		<pubDate>Tue, 02 Feb 2010 06:19:50 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[brilliant software]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[JavaScript programmer]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[web apps]]></category>
		<category><![CDATA[web developers]]></category>

		<guid isPermaLink="false">/?p=999</guid>
		<description><![CDATA[Firebug and the console object Although my impression is that most of the web developers use Firefox and most of them are using Firebug, I’m not sure that they use the full potential of this brilliant software. Firebug&#8217;s console view Firebug is a very powerful tool helping those like me doing his job. But what’s &#8230; <a href="/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/" class="more-link">Continue reading <span class="screen-reader-text">Profiling JavaScript with Firebug. console.profile() &#038; console.time()!</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/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2010/02/12/how-to-detect-a-variable-existence-in-javascript/" rel="bookmark" title="How to detect a variable existence in JavaScript?">How to detect a variable existence in JavaScript? </a></li>
<li><a href="/2012/01/24/javascript-performance-for-vs-while/" rel="bookmark" title="JavaScript Performance: for vs. while">JavaScript Performance: for vs. while </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Firebug and the console object</h2>
<p>Although my impression is that most of the web developers use Firefox and most of them are using Firebug, I’m not sure that they use the full potential of this brilliant software.</p>
<p><a href="/wp-content/uploads/2010/01/logging.gif"><img class="aligncenter size-full wp-image-1001" title="logging" src="/wp-content/uploads/2010/01/logging.gif" alt="" width="430" height="195" srcset="/wp-content/uploads/2010/01/logging.gif 430w, /wp-content/uploads/2010/01/logging-300x136.gif 300w" sizes="(max-width: 430px) 100vw, 430px" /></a></p>
<p><em>Firebug&#8217;s console view</em></p>
<p>Firebug is a very powerful tool helping those like me doing his job. But what’s behind the mostly used Firebug’s tools and what’s in the API.</p>
<h2>console.log()</h2>
<p>For a typical JavaScript programmer the console.log() function is one of his best friends. It can dump useful information in the console tab of the Firebug making everything quite clear. But have you ever asked yourself how to improve your code, how to measure its performance against some constructions.</p>
<h2>Performance of JavaScript</h2>
<p>I’m sure many of us have read enough articles out in the web about JS performance. Nowadays when the web apps become bigger and bigger, this topic is rising from the bottom of the interesting topics pool. Now everybody’s concerned about it’s app performance and speed.</p>
<p>You’ve probably heart about some basic advices. What to use, what not to use. In a short example I’ll mention only that everybody knows that .appendChild is far slower than the innerHTML. But why is that? How can be sure it’s true.</p>
<p>As I wrote recently you should instantiate your new arrays in javascript with the following construction:</p>
<blockquote>
<pre>var a = [];</pre>
</blockquote>
<p>instead of:</p>
<blockquote>
<pre>var a = new Array();</pre>
</blockquote>
<p>but as I’ll write here that’s not always true.</p>
<h2>console.profile()</h2>
<p>One of the useful methods of the Firebug’s console object is the profile() method. It gives you the power to measure timing and performance of any JS function. As described in the Firebug’s web page:</p>
<p><em>The high-fi approach is to use the JavaScript profiler. Just call console.profile() before the code you want to measure, and then console.profileEnd() afterwards. Firebug will log a detailed report about how much time was spent in every function call in between.</em></p>
<p>With the simple construction like:</p>
<blockquote>
<pre>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;
    myFunc = function() {
        var a = [];
    }				

   console.profile();
   myFunc();
   console.profileEnd();
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</blockquote>
<p><a href="/wp-content/uploads/2010/01/firebug-profile.png"><img class="aligncenter size-full wp-image-1000" title="firebug-profile" src="/wp-content/uploads/2010/01/firebug-profile.png" alt="" width="430" height="152" srcset="/wp-content/uploads/2010/01/firebug-profile.png 430w, /wp-content/uploads/2010/01/firebug-profile-300x106.png 300w" sizes="(max-width: 430px) 100vw, 430px" /></a></p>
<p><em>Firebug&#8217;s profile output</em></p>
<p>The simple problem is that thus you cannot just measure some code that’s not a function. This will result in empty profile output in the console&#8217;s view:</p>
<p><a href="/wp-content/uploads/2010/01/no-activity.png"><img class="alignleft size-full wp-image-1002" title="no-activity" src="/wp-content/uploads/2010/01/no-activity.png" alt="" width="231" height="60" /></a></p>
<p>But hopefully there comes the other method of the console object.</p>
<h2>console.time()</h2>
<p>It gives anything you’d like to know even if it’s not closed into a function.</p>
<p><em><strong>Note</strong>: remember that both profile and time methods goes with their related profileEnd and timeEnd methods. You’re supposed to enclose the chunk of code you measure with that to be sure that the Firebug’s console will stop the profilers on time. </em></p>
<p><em><span style="font-style: normal;">Now you can simply ask the profiler: what is faster?</span></em></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/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2010/02/12/how-to-detect-a-variable-existence-in-javascript/" rel="bookmark" title="How to detect a variable existence in JavaScript?">How to detect a variable existence in JavaScript? </a></li>
<li><a href="/2012/01/24/javascript-performance-for-vs-while/" rel="bookmark" title="JavaScript Performance: for vs. while">JavaScript Performance: for vs. while </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a jQuery plugin &#8211; (part 2). Sample plugin.</title>
		<link>/2010/02/01/writing-a-jquery-plugin-part-2-sample-plugin/</link>
		<comments>/2010/02/01/writing-a-jquery-plugin-part-2-sample-plugin/#respond</comments>
		<pubDate>Mon, 01 Feb 2010 05:21:45 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[$.log]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">/?p=791</guid>
		<description><![CDATA[To be breve I’ll write some sample code and quickly describe it afterwards. So what’s a plugin. Lets make a simple logging plugin that overrides the console.log function and prevents MSIE browser to throw an error when this function misses. The thing I’d like to achieve is something like: $.log(‘my message’); when I call it &#8230; <a href="/2010/02/01/writing-a-jquery-plugin-part-2-sample-plugin/" class="more-link">Continue reading <span class="screen-reader-text">Writing a jQuery plugin &#8211; (part 2). Sample plugin.</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/11/13/writing-a-jquery-plugin-part-1-good-practices/" rel="bookmark" title="Writing a jQuery plugin &#8211; (part 1). Good practices!">Writing a jQuery plugin &#8211; (part 1). Good practices! </a></li>
<li><a href="/2009/07/27/jquery-debug-plugin/" rel="bookmark" title="jQuery debug plugin">jQuery debug plugin </a></li>
<li><a href="/2009/11/10/jquery-css-functions-part-1-offset/" rel="bookmark" title="jQuery CSS functions. Part 1 &#8211; offset()">jQuery CSS functions. Part 1 &#8211; offset() </a></li>
<li><a href="/2010/02/17/clickoutside-jquery-plugin/" rel="bookmark" title="clickoutside jQuery plugin">clickoutside jQuery plugin </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>To be breve I’ll write some sample code and quickly describe it afterwards. So what’s a plugin. Lets make a simple logging plugin that overrides the console.log function and prevents MSIE browser to throw an error when this function misses.</p>
<p>The thing I’d like to achieve is something like:</p>
<blockquote>
<pre>$.log(‘my message’);</pre>
</blockquote>
<p>when I call it from a pure jQuery code.</p>
<blockquote>
<pre>function log( msg ) {
   console.log &amp;&amp; console.log(msg);
}</pre>
</blockquote>
<p>That code looks quite correct, but to make all this into a jQuery plugin will need something more.</p>
<blockquote>
<pre>(function(jquery) {

   var log = function( msg ) {
      console.log &amp;&amp; console.log(msg);
   };

   jquery.log = log;

}(jQuery));</pre>
</blockquote>
<p>After that we can call the <strong>$.log</strong> function with success and to perform logging of everything we want into the Firebug’s console.</p>
<p>The simple technique used here is a JavaScript closure and simple exportation of the single function log.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/11/13/writing-a-jquery-plugin-part-1-good-practices/" rel="bookmark" title="Writing a jQuery plugin &#8211; (part 1). Good practices!">Writing a jQuery plugin &#8211; (part 1). Good practices! </a></li>
<li><a href="/2009/07/27/jquery-debug-plugin/" rel="bookmark" title="jQuery debug plugin">jQuery debug plugin </a></li>
<li><a href="/2009/11/10/jquery-css-functions-part-1-offset/" rel="bookmark" title="jQuery CSS functions. Part 1 &#8211; offset()">jQuery CSS functions. Part 1 &#8211; offset() </a></li>
<li><a href="/2010/02/17/clickoutside-jquery-plugin/" rel="bookmark" title="clickoutside jQuery plugin">clickoutside jQuery plugin </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/02/01/writing-a-jquery-plugin-part-2-sample-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
