<?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>chart &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/chart/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>Speed Up the jQuery Code: Selectors&#8217; Cache</title>
		<link>/2010/06/19/speed-up-the-jquery-code-selectors-cache/</link>
		<comments>/2010/06/19/speed-up-the-jquery-code-selectors-cache/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 08:36:08 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[measurement]]></category>
		<category><![CDATA[results]]></category>
		<category><![CDATA[selectors]]></category>
		<category><![CDATA[tables]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">/?p=1630</guid>
		<description><![CDATA[Short Experiment Here&#8217;s a short optimization of a small chunk of jQuery code. The experiment was to increment the number of DOM element access. In this case this was a change of the innerHTML property &#8211; using the $.html() method. I&#8217;ve measured the result with the console.time() method and thus I expect correct results for &#8230; <a href="/2010/06/19/speed-up-the-jquery-code-selectors-cache/" class="more-link">Continue reading <span class="screen-reader-text">Speed Up the jQuery Code: Selectors&#8217; Cache</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/11/04/jquery-css-selectors-change-one-or-more-css-properties/" rel="bookmark" title="jQuery CSS selectors. Change one or more CSS properties!">jQuery CSS selectors. Change one or more CSS properties! </a></li>
<li><a href="/2010/02/09/optimizing-openlayers-speed-up-markers-load-time/" rel="bookmark" title="Optimizing OpenLayers. Speed up markers load time!">Optimizing OpenLayers. Speed up markers load 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/06/24/zend-framework-inject-javascript-code-in-a-actionview/" rel="bookmark" title="Zend Framework: Inject JavaScript Code in a Action/View">Zend Framework: Inject JavaScript Code in a Action/View </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Short Experiment</h2>
<p>Here&#8217;s a short optimization of a small chunk of jQuery code. The experiment was to increment the number of DOM element access. In this case this was a change of the innerHTML property &#8211; using the $.html() method.</p>
<p>I&#8217;ve measured the result with the console.time() method and thus I expect correct results for both cases. In the first case I directly call the jQuery selectors&#8217; html() method:</p>
<pre lang="javascript">
for (var i = 0; i < 10000; i++) {
    $('#container').html(i);
}
</pre>
<p>While in the second case I "cache" it before the loop:</p>
<pre lang="javascript">
var t = $('#container');
for (var i = 0; i < 10000; i++) {
    t.html(i);
}
</pre>
<p>and here's the full code in the first case:</p>
<pre lang="html4strict">
<html>
<head>
    <title>jQuery Cache</title>
</head>
<body>

<div id="container"></div>

<script src="/scripts/library.js"></script>
<script>

$(document).ready(function() {

    console.time('foo');
    for (var i = 0; i < 10000; i++) {
        $('#container').html(i);
    }
    console.timeEnd('foo');
});
</script>
</body>
</html>
</pre>
<h2>The Results</h2>
<p>As expected the second "cached" approach gave better results. With the increment of the iterations the second method began to be slightly better than the first one. That's not so much, but imagine you have more than one selector in the loop's body?</p>
<h3>Numbers:</h3>
<p><img src="/wp-content/uploads/2010/06/table.png" /><br />
Note that in the time is in ms, and, yes, this is not so much, but when you deal with large data and you've more than one selector in the loop's body, this can be critical!</p>
<h3>Graphics:</h3>
<p><img src="/wp-content/uploads/2010/06/chart.png" /></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/11/04/jquery-css-selectors-change-one-or-more-css-properties/" rel="bookmark" title="jQuery CSS selectors. Change one or more CSS properties!">jQuery CSS selectors. Change one or more CSS properties! </a></li>
<li><a href="/2010/02/09/optimizing-openlayers-speed-up-markers-load-time/" rel="bookmark" title="Optimizing OpenLayers. Speed up markers load time!">Optimizing OpenLayers. Speed up markers load 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/06/24/zend-framework-inject-javascript-code-in-a-actionview/" rel="bookmark" title="Zend Framework: Inject JavaScript Code in a Action/View">Zend Framework: Inject JavaScript Code in a Action/View </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/06/19/speed-up-the-jquery-code-selectors-cache/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
