<?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>(function() { &#187; benchmark</title>
	<atom:link href="http://maxb.net/blog/tag/benchmark/feed/" rel="self" type="application/rss+xml" />
	<link>http://maxb.net/blog</link>
	<description>// MAXB.NET LABS</description>
	<lastBuildDate>Mon, 16 May 2011 19:12:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Benchmark – YCodaSlider 2.0rc2</title>
		<link>http://maxb.net/blog/2008/05/23/benchmark-ycodaslider-20rc2/</link>
		<comments>http://maxb.net/blog/2008/05/23/benchmark-ycodaslider-20rc2/#comments</comments>
		<pubDate>Fri, 23 May 2008 18:51:19 +0000</pubDate>
		<dc:creator>Massimiliano Balestrieri</dc:creator>
				<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[ycodaslider]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://maxb.net/blog/?p=44</guid>
		<description><![CDATA[Ho corretto numerosi bug. Pulito il codice. Ora esegue mediamente in 70-80ms su Firefox 2.0 settando una larghezza iniziale. La velocità è praticamente triplicata. BENCHMARK: PRIMA METODI: PRIMA Benchmark 1 Benchmark 2 YCodaSlider 2.0rc2 &#8211; SVN &#8211; rev 121 YCodaSlider &#8230; <a href="http://maxb.net/blog/2008/05/23/benchmark-ycodaslider-20rc2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ho corretto numerosi bug. Pulito il codice. Ora esegue mediamente in 70-80ms su Firefox 2.0 settando una larghezza iniziale. La velocità è praticamente triplicata.</p>
<p>BENCHMARK:</p>
<p><a href='http://maxb.net/blog/wp-content/uploads/2008/05/rc2-73ms.png'><img src="http://maxb.net/blog/wp-content/uploads/2008/05/rc2-73ms.png" alt="" title="rc2-73ms" class="alignnone size-full wp-image-49" /></a></p>
<p>PRIMA</p>
<p><a href='http://maxb.net/blog/wp-content/uploads/2008/05/rc1-186.png'><img src="http://maxb.net/blog/wp-content/uploads/2008/05/rc1-186.png" alt="" title="rc1-186" class="alignnone size-full wp-image-51" /></a></p>
<p>METODI:</p>
<p><a href='http://maxb.net/blog/wp-content/uploads/2008/05/rc2-methods2.png'><img src="http://maxb.net/blog/wp-content/uploads/2008/05/rc2-methods2.png" alt="" title="rc2-methods2" class="alignnone size-full wp-image-50" /></a></p>
<p>PRIMA</p>
<p><a href='http://maxb.net/blog/wp-content/uploads/2008/05/prima1.png'><img src="http://maxb.net/blog/wp-content/uploads/2008/05/prima1.png" alt="" title="prima1" class="alignnone size-full wp-image-45" /></a></p>
<p><a href="http://www.maxb.net/scripts/benchmark/24.html">Benchmark 1</a><br />
<a href="http://www.maxb.net/scripts/benchmark/26.html">Benchmark 2</a><br />
<a href="http://www.maxb.net/scripts/benchmark/lib/ycodaslider-2.0.svn.js">YCodaSlider 2.0rc2 &#8211; SVN &#8211; rev 121</a></p>
<p><a href="/blog/2008/05/11/ycodaslider-20/">YCodaSlider 2.0rc2 out.</a><br />
<a href="/scripts/ycodaslider-2.0/include/demo/">DEMO SITE</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maxb.net/blog/2008/05/23/benchmark-ycodaslider-20rc2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Benchmark – YCodaslider 2.0 refactory</title>
		<link>http://maxb.net/blog/2008/05/23/benchmark-ycodaslider-20-refactory/</link>
		<comments>http://maxb.net/blog/2008/05/23/benchmark-ycodaslider-20-refactory/#comments</comments>
		<pubDate>Fri, 23 May 2008 10:38:32 +0000</pubDate>
		<dc:creator>Massimiliano Balestrieri</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[ycodaslider]]></category>
		<category><![CDATA[benchmark]]></category>

		<guid isPermaLink="false">http://maxb.net/blog/?p=41</guid>
		<description><![CDATA[PRIMA: DOPO: Dal lavoro sui metodi ho capito cosa rende lento il plugin. Ho meglio più che lento, cosa inficia maggiormente sul tempo di esecuzione di YCodaSlider 2.0: Benchmark Il metodo nav() impiega circa 130ms per essere eseguito (firefox 2.0). &#8230; <a href="http://maxb.net/blog/2008/05/23/benchmark-ycodaslider-20-refactory/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>PRIMA:</p>
<p><a href='http://maxb.net/blog/wp-content/uploads/2008/05/prima.png'><img src="http://maxb.net/blog/wp-content/uploads/2008/05/prima.png" alt="" title="prima" class="alignnone size-full wp-image-43" /></a></p>
<p>DOPO:</p>
<p><a href='http://maxb.net/blog/wp-content/uploads/2008/05/dopo.png'><img src="http://maxb.net/blog/wp-content/uploads/2008/05/dopo.png" alt="" title="dopo" class="alignnone size-full wp-image-42" /></a></p>
<p>Dal lavoro sui metodi ho capito cosa rende lento il plugin. Ho meglio più che lento, cosa inficia maggiormente sul tempo di esecuzione di YCodaSlider 2.0:</p>
<p><a href="http://www.maxb.net/scripts/benchmark/13.html">Benchmark</a></p>
<p>Il metodo nav() impiega circa 130ms per essere eseguito (firefox 2.0).</p>
<pre class="brush: jscript; title: ; notranslate">
    nav    :   function(el){
        var jViewer = jQuery(&quot;div.yslider-viewer&quot;,el);
        jViewer.before('&lt;div class=&quot;yslider-navl&quot;&gt;&lt;a href=&quot;#&quot;&gt;Left&lt;/a&gt;&lt;/div&gt;');
        jViewer.after('&lt;div class=&quot;yslider-navr&quot;&gt;&lt;a href=&quot;#&quot;&gt;Right&lt;/a&gt;&lt;/div&gt;');
        jViewer.before('&lt;div class=&quot;yslider-nav&quot;&gt;&lt;ul&gt;&lt;\/ul&gt;&lt;/div&gt;');
        var jNav = jQuery(&quot;div.yslider-nav ul&quot;,el);
        var jPanels = jQuery(&quot;div.yslider-panel&quot;,el);
        jPanels.each(function(n) {
            var lp = jQuery(&quot;div.yslider-panelwrapper&quot;,this).attr(&quot;title&quot;) || (n+1);
            if(el.ycodaslider.options.history){
                 jQuery('&lt;li&gt;&lt;a href=&quot;#' + (n + 1) + '&quot;&gt;' + lp + '&lt;/a&gt;&lt;/li&gt;').appendTo(jNav);
            }else{
                jQuery('&lt;li&gt;&lt;a href=&quot;#&quot;&gt;' + lp + '&lt;/a&gt;&lt;/li&gt;').appendTo(jNav).click(function(){
                   return false;
                });
            }
        });
        //setto la larghezza del menu qui.
        jNav.find(&quot;li&quot;).each(function(nr){
            el.ycodaslider.nw += jQuery(this).width();
        });
        if(el.ycodaslider.options.width)
            jNav.parent().css({&quot;width&quot; : el.ycodaslider.options.width});
        else
            jNav.parent().css(&quot;width&quot; , el.ycodaslider.nw);

    }
</pre>
<p>Commentando questo ottengo un centinaio di ms di risparmio</p>
<pre class="brush: jscript; title: ; notranslate">
//questo costa 100ms!
jNav.find(&quot;li&quot;).each(function(nr){
    el.ycodaslider.nw += jQuery(this).width();
});
</pre>
<p>Innanzitutto non c&#8217;è bisogno di calcolare la larghezza dei tag LI per avere una corretta larghezza del contenitore.<br />
<strong>In ogni caso il metodo width applicato ad un elemento che non ha una larghezza impostata da css è notevolmente lento.</strong><br />
Penso che calcoli il numero di caratteri per il font per ottenere una larghezza in pixels.</p>
<blockquote><p>Non usare il metodo width se non è settata la proprietà css width.</p></blockquote>
<p>Ora il metodo viene eseguito in 12ms. </p>
<p><a href="http://www.maxb.net/scripts/benchmark/14.html">Benchmark</a></p>
<blockquote><p>el.ycodaslider.nw = el.ycodaslider.pc * 2; </p></blockquote>
<blockquote><p>el.ycodaslider.nw = el.ycodaslider.pw;//el.ycodaslider.pc * 2 ? </p></blockquote>
<p>Veniva calcolata la larghezza del navigatore moltiplicando per due il numero dei pannelli. Perchè?<br />
Non lo so. Refuso.</p>
<p>In realtà la larghezza del navigartore è uguale alla larghezza del pannello.</p>
<p>Correggendo questo valore ho modificato il metodo nav al fondo con questo:</p>
<pre class="brush: jscript; title: ; notranslate">
if(el.ycodaslider.options.width){
      jNav.parent().css({&quot;width&quot; : el.ycodaslider.options.width});
}else{
     jNav.parent().css(&quot;width&quot; , el.ycodaslider.nw );
}
</pre>
<p>Ecco il benchmark aggiornato con il metodo nav e il metodo count corretti. </p>
<p><a href="http://www.maxb.net/scripts/benchmark/15.html">Benchmark</a></p>
<p>Notare come il lunghissimo metodo bindings non pesi niente. Grazie alle clousure infatti praticamente il codice viene attaccato all&#8217;handler e verrà valutato solo al bind dell&#8217;evento.</p>
<p>Ma per questo bisogna ringraziare jQuery e John Resig.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxb.net/blog/2008/05/23/benchmark-ycodaslider-20-refactory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Benchmark 1.0 – Peso dei metodi</title>
		<link>http://maxb.net/blog/2008/05/23/benchmark-10-methods-weight/</link>
		<comments>http://maxb.net/blog/2008/05/23/benchmark-10-methods-weight/#comments</comments>
		<pubDate>Fri, 23 May 2008 09:14:40 +0000</pubDate>
		<dc:creator>Massimiliano Balestrieri</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[ycodaslider]]></category>

		<guid isPermaLink="false">http://maxb.net/blog/?p=36</guid>
		<description><![CDATA[Ho portato avanti l&#8217;esperimento del plugin &#8220;benchmark&#8221;. Modificando il plugin benchmark, ho trovato un sistema accettabile per adattare il plugin creato al calcolo del &#8220;peso&#8221; dei metodi di un plugin. Qui la verisione usata: svn metodi Ecco il risultato: Il &#8230; <a href="http://maxb.net/blog/2008/05/23/benchmark-10-methods-weight/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ho portato avanti l&#8217;esperimento del plugin &#8220;benchmark&#8221;.</p>
<p>Modificando il plugin benchmark, ho trovato un sistema accettabile per adattare il plugin creato al calcolo del &#8220;peso&#8221; dei metodi di un plugin. Qui la verisione usata: <a href="/scripts/benchmark/benchmark/benchmark.svn.js">svn</a></p>
<p><a href="/scripts/benchmark/13.html">metodi </a></p>
<p>Ecco il risultato:</p>
<p><a href='http://maxb.net/blog/wp-content/uploads/2008/05/methods1.png'><img src="http://maxb.net/blog/wp-content/uploads/2008/05/methods1.png" alt="" title="methods1"  class="alignnone size-full wp-image-38" /></a></p>
<p>Il widget non è nascosto. E&#8217; visibile. <strong>Ho capito che lavorare su elementi nascosti è sviante.</strong>. E&#8217; vero ci impiega meno, ma se utilizzi i metodi width() e height() questi forniranno dati sbagliati e di fondo il codice sbaglia nellìeseguire le funzioni.</p>
<p>I risultati mi sembrano attendibili. Ogni metodo ha un suo peso.</p>
<table class="rs">
<tr>
<th>&nbsp;</th>
<th>YCodaSlider 2.0</th>
</tr>
<tr>
<th>build</th>
<td>0 ms</td>
</tr>
<tr>
<th>gui</th>
<td>35 ms</td>
</tr>
<tr>
<th>count</th>
<td>26 ms</td>
</tr>
<tr>
<th>init</th>
<td>3 ms</td>
</tr>
<tr>
<th>start</th>
<td>0 ms</td>
</tr>
<tr>
<th>nav</th>
<td>168 ms</td>
</tr>
<tr>
<th>bindings</th>
<td>7 ms</td>
</tr>
<tr>
<th>defaults</th>
<td>2 ms</td>
</tr>
</table>
<p>I test sono stati effettuati su firefox 2.0 con firebug attivo.<br />
Con firefox 3.0 gli stessi test sono nettamente più veloci (evviva!)</p>
<p>Nav è il primo metodo da rifattorizzare.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxb.net/blog/2008/05/23/benchmark-10-methods-weight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Benchmark 1.0</title>
		<link>http://maxb.net/blog/2008/05/21/benchmark-10/</link>
		<comments>http://maxb.net/blog/2008/05/21/benchmark-10/#comments</comments>
		<pubDate>Wed, 21 May 2008 13:54:43 +0000</pubDate>
		<dc:creator>Massimiliano Balestrieri</dc:creator>
				<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://maxb.net/blog/?p=29</guid>
		<description><![CDATA[DOWNLOAD PACKED Perchè questo plugin? Secondo molti se io salvo un dato in un elemento DOM all&#8217;interno di una proprietà &#8220;expando&#8221; in fase di lettura sarò più veloce rispetto ad avere lo stesso dato in un attributo html. Il plugin &#8230; <a href="http://maxb.net/blog/2008/05/21/benchmark-10/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="/scripts/benchmark/benchmark/benchmark.js" target="_blank">DOWNLOAD</a></li>
<li><a href="/scripts/benchmark/benchmark/benchmark.pack.js" target="_blank">PACKED</a></li>
</ul>
<p>Perchè questo plugin?<br />
Secondo molti se io salvo un dato in un elemento DOM all&#8217;interno di una proprietà &#8220;expando&#8221; in fase di lettura sarò più veloce rispetto ad avere lo stesso dato in un attributo html.</p>
<p><a href="http://maxb.net/blog/wp-content/uploads/2008/05/expvsattr.png"><img class="alignnone size-full wp-image-30" title="expvsattr" src="http://maxb.net/blog/wp-content/uploads/2008/05/expvsattr.png" alt="" width="500" height="156" /></a></p>
<p>Il plugin sembra confermare questa tesi.</p>
<p>Intanto cosa indica il grafico. Se spiego il grafico sarà più semplice capire come usare il plugin e testarlo per i vostri scopi.</p>
<p>Il grafico indica che all&#8217;aumentare degli elementi html su una pagina (in questo caso da uno a trenta immagini) effettivamente leggere un valore da un attributo html o leggere un valore dalla proprietà di un oggetto (lo stesso oggetto d&#8217;altra parte) sono due operazioni diverse e effettivamente una è più veloce dell&#8217;altra. E ci mancherebbe! La prima è un funzione di lettura/scrittura (oltretutto jQuery over DOM). La seconda è una lettura/scrittura nativa di una proprietà di un oggetto.</p>
<p>Le funzioni:</p>
<pre class="brush: jscript; title: ; notranslate">
var mywrite = function(ref, serie){
    if(serie == 1)
        ref.original = jQuery(ref).attr(&quot;src&quot;);
    else
        jQuery(ref).attr(&quot;original&quot;, jQuery(ref).attr(&quot;src&quot;));
}
var myread = function(ref, serie){
    if(serie  == 1){
        var read = ref.original;
        read = null;
    }else{
        var read = jQuery(ref).attr(&quot;original&quot;);
    }
}
</pre>
<p>il parametro serie indica quale test sto eseguendo. In questo caso io voglio un confronto tra &#8220;due alternative&#8221;. Avessi scritto delle funzioni più complesse potevo avere più test, e quindi più serie.<br />
(Probabilmente cercando di influire il meno possibile sul test. La strada dell&#8217;if magari è da rivedere).</p>
<p>Test 0:<br />
Scrittura:</p>
<blockquote><p>jQuery(ref).attr(&#8220;original&#8221;, jQuery(ref).attr(&#8220;src&#8221;));</p></blockquote>
<p>Lettura:</p>
<blockquote><p>var read = jQuery(ref).attr(&#8220;original&#8221;);</p></blockquote>
<p>Test 1:</p>
<p>Scrittura:</p>
<blockquote><p>ref.original = jQuery(ref).attr(&#8220;src&#8221;);</p></blockquote>
<p>Lettura:</p>
<blockquote><p>var read = ref.original;</p></blockquote>
<p>Ma come faccio a far eseguire queste funzioni?<br />
Queste funzioni vengono passate al benchmark: vediamo come.</p>
<p>Innanzitutto questi benchmark sono &#8220;orientati al DOM&#8221; nel senso che io voglio testare la velocità di una certa azione su una pagina web.<br />
Quindi mi serve una sorta di template html da creare per poi applicare la funzione.</p>
<pre class="brush: jscript; title: ; notranslate">
var html = jQuery('&lt;img alt=&quot;new Mikado logo 600 3D&quot;  src=&quot;http://maxb.net/repository/images/14.jpg&quot; /&gt;');
</pre>
<p>A questo punto setto il benchmark:</p>
<pre class="brush: jscript; title: ; notranslate">
Benchmark.settings({
    maxc    : 30,
    args    : [0,1] ,
    mod     : 10,
    prepare : html
});
</pre>
<p>Questi settaggi mi dicono che</p>
<ul>
<li>io ho due serie di test (<strong>args</strong>).</li>
<li>Che voglio testare su una pagina web formata da 30 elementi (<strong>maxc</strong>).</li>
<li>In realtà i test verranno eseguiti con un elemento in più alla volta fino ad arrivare ad avere 30 elementi. Il parametro mod mi permette di saltare ogni N elementi. In questo caso verranno eseguiti 3 test uno con 10, uno con 20, uno con 30 elementi  (<strong>mod</strong>)</li>
<li>Che l&#8217;html da creare prima del test è contenuto nella variabile html  (<strong>prepare</strong>)</li>
</ul>
<p>Ecco il codice per il benchmark</p>
<pre class="brush: jscript; title: ; notranslate">
Benchmark.each(function(nr, serie){
    jQuery(selector).benchmark({
        test    :   [ func1, func2 ] //....
    }, nr, serie);
});
</pre>
<p>La parte da personalizzare è l&#8217;array con i nomi di funzioni (o con funzioni anonime).</p>
<p>E il selettore.<br />
Nel mio test ho dato da creare delle immagini. Il selettore sarà &#8220;img&#8221;.</p>
<pre class="brush: jscript; title: ; notranslate">
Benchmark.each(function(nr, serie){
    jQuery('img').benchmark({
        test    :   [ mywrite , myread ]
    }, nr, serie);
});
</pre>
<p>Alla fine dei test verrà visualizzato tramite GOOGLE API CHARTS un grafico per capire al volo i risultati.</p>
<p>Vedere gli altri esempi :</p>
<ul>
<li><a href="/scripts/benchmark/1.html" target="_blank">ATTR VS EXPANDO</a></li>
<li><a href="/scripts/benchmark/1b.html" target="_blank">ATTR VS EXPANDO (funzioni anonime passate al benchmark)</a></li>
<li><a href="/scripts/benchmark/2.html" target="_blank">YCODASLIDER no pack</a></li>
<li><a href="/scripts/benchmark/3.html" target="_blank">YCODASLIDER pack version</a></li>
<li><a href="/scripts/benchmark/4.html" target="_blank">Chili 2.0 plugin (Velocissimo!)</a></li>
<li><a href="/scripts/benchmark/5.html" target="_blank">YCodaSlider Benchmark Explanation &#8211; NOT VALID FOR RESULTS</a></li>
<li><a href="/scripts/benchmark/6.html" target="_blank">CodaSlider Benchmark Explanation &#8211; NOT VALID FOR RESULTS</a></li>
<li><a href="/scripts/benchmark/7.html" target="_blank">CodaSlider Benchmark</a></li>
<li><a href="/scripts/benchmark/8.html" target="_blank">YCodaSlider Benchmark</a></li>
<li><a href="/scripts/benchmark/9.html" target="_blank">YCodaSlider Benchmark &#8211; Stress &#8211; 50 slider</a></li>
<li><a href="/scripts/benchmark/10.html" target="_blank">CodaSlider Benchmark &#8211; Stress &#8211; 50 slider</a></li>
</ul>
<p>Il test mi dice che il pack dei javascript non influisce sulla velocità.<br />
Devo provare con le librerie jQuery UI.</p>
<p>Un confronto tra coda-slider 1.1.1 di Niall Doherty e il mio YCodaSlider.<br />
<strong>Tutti questi dati non hanno alcuna valenza. Spero che mi permettano di capire dove è possibile migliorare le prestazioni e evitare memory leak. (Tra l&#8217;altro il mio plugin su poche istanze è più lento.)<br />
</strong></p>
<table class="rs">
<tr>
<th>&nbsp;</th>
<th>YCodaSlider 2.0</th>
<th>Coda-Slider 1.1.1</th>
</tr>
<tr>
<th>5</th>
<td>459ms</td>
<td>337ms</td>
</tr>
<tr>
<th>10</th>
<td>908ms</td>
<td>759ms</td>
</tr>
<tr>
<th>20</th>
<td>2069ms</td>
<td>2316ms</td>
</tr>
<tr>
<th>30</th>
<td>3497ms</td>
<td>4124ms</td>
</tr>
<tr>
<th>40</th>
<td>4327ms</td>
<td>6278ms</td>
</tr>
<tr>
<th>50</th>
<td>5386ms</td>
<td>9067ms</td>
</tr>
</table>
<blockquote><p>$Date: 2008-05-21 20:48:10 +0200 (mer, 21 mag 2008) $<br />
$Rev: 106 $</p>
<p>corretto 2 bachi:<br />
- il clone non può avere la stessa classe del target. Se si bisogna invocare il benchmark con un prefisso sul selettore target : Benchmark.prefix() + &#8220;.target&#8221;<br />
- se il selettore seleziona più elementi di quanti il benchmark se ne aspettasse il benchmark non viene eseguito</p>
<p>TODO:<br />
l&#8217;oggetto da clonare (options.prepare) deve poter essere un array in modo che ogni serie possa avere il suo clone da appendere.</p></blockquote>
<pre class="brush: jscript; title: ; notranslate">
/*
 *
 * Benchmark plugin 1.0
 * $Date: 2008-05-21 20:48:10 +0200 (mer, 21 mag 2008) $
 * $Rev: 106 $
 * @requires jQuery v1.2.3
 *
 * Copyright (c) 2008 Massimiliano Balestrieri
 * Examples and docs at: http://maxb.net/blog/
 * Licensed GPL licenses:
 * http://www.gnu.org/licenses/gpl.html
 *
 */

//http://www.dustindiaz.com/basement/sugar-arrays.html
Array.prototype.indexOf = function(el, start) {
    var start = start || 0;
    for ( var i=0; i &lt; this.length; ++i ) {
        if ( this[i] === el ) {
            return i;
        }
    }
    return -1;
};

if(!window.Benchmark)
	Benchmark = {};

Benchmark = {
	show		:	false,
	start		:	false,
	finish		:	false,
	elapsed		:	false,
	flag		:	false,
	impossible	:	false,
	url			:	'http://chart.apis.google.com/chart?',
	maxv		:	0,
	maxc		:	0,
	data		:	[],
	labels		:	[],
	api			:	{},
	options 	: 	{},
	settings	:	function(options){
		Benchmark.options = jQuery.extend({
			maxc 	: 1	,//maxc : è il limite al ciclo
			args	: false	,//serie del grafico, ciclo esterno. passa parametro
			mod		: 1,	 //il benchmark salta ogni?
			prepare : false,
			clean   : true
		}, options);

		Benchmark.maxc = Benchmark.options.maxc;

		if(Benchmark.options.args === false)
			Benchmark.impossible = true;
	},
	chartapi	:	function(options){
		//http://chart.apis.google.com/chart
		Benchmark.api = jQuery.extend({
			dimensions 	: &quot;1000x300&quot;,
			chxt		: &quot;x,y&quot;,
			chds		: &quot;0,&quot;,
			chxr1		: &quot;0,0,&quot;,
			chxr2		: &quot;1,0,&quot;,
			cht			: &quot;lc&quot;,
			labels		: &quot;&quot;,
			chco		: &quot;ff0000,00ff00&quot;
		}, options);
		Benchmark.make_url();
	},
	chart	:	function(options){
		if(Benchmark.flag === false)
			Benchmark.chartapi(options);

		var dim = Benchmark.api.dimensions.split(&quot;x&quot;);
		jQuery(&quot;body&quot;).append(&quot;&lt;p&gt;&quot;+Benchmark.url+&quot;&lt;/p&gt;&quot;);

		jQuery(&quot;body&quot;).append('&lt;img width=&quot;'+dim[0]+'&quot; height=&quot;'+dim[1]+'&quot; src=&quot;'+Benchmark.url+'&quot; /&gt;');
	},
	make_url:	function(){
		Benchmark.url	+=	'chs=' 	+ Benchmark.api.dimensions 	+ '&amp;amp;';
		Benchmark.url	+=	'chxt=' + Benchmark.api.chxt 		+ '&amp;amp;';
		Benchmark.url	+=	'chds=' + Benchmark.api.chds 		+ Benchmark.maxv	+	'&amp;amp;';
		Benchmark.url	+=	'chxr='	+ Benchmark.api.chxr1 		+ Benchmark.maxc	+	'|'	+ Benchmark.api.chxr2 + Benchmark.maxv + '&amp;amp;';
		Benchmark.url	+=	'chl=0|' 	+ Benchmark.labels.join(&quot;|&quot;)	+ '&amp;amp;';

		var data = '';
		for(serie in Benchmark.data)
			data += &quot;0,&quot; + Benchmark.data[serie].join(&quot;,&quot;) + &quot;|&quot;;
		data = data.substr(0, data.lastIndexOf(&quot;|&quot;));			

		Benchmark.url	+=	'chd=t:' 	+ data	+	'&amp;amp;';

		Benchmark.url	+=	'cht=' 	+ Benchmark.api.cht			+ '&amp;amp;';
		Benchmark.url	+=	'chdl=' + Benchmark.api.labels.join(&quot;|&quot;) + '&amp;amp;';
		Benchmark.url	+=	'chco=' + Benchmark.api.chco 		;
	},
	prepare :   function(p){
        jQuery('&lt;div id=&quot;benchmark-dom'+p+'&quot;&gt;').hide().appendTo(&quot;body&quot;);
        if(Benchmark.show)
        	jQuery('#benchmark-dom'+p).show();
	},
	serie 	:	function(p, arg){
		jQuery('#benchmark-dom'+p).append('&lt;div id=&quot;serie-'+p + '-' + arg +' /&gt;');
	},
	append  :	function(p, arg){
        for(var x = 1;x &lt;= p; x++){
			var a = Benchmark.options.prepare.attr(&quot;id&quot;, &quot;test-&quot; + p + '-' + arg + '-' + x).clone();
    		jQuery(a).appendTo('#serie-'+p+'-'+arg);
		}
	},
	clean	:	function(p, serie){
		jQuery('#serie-' + p + '-'+ serie).empty();
	},
	stop	:	function(benchmarkid, serie){

        Benchmark.finish = new Date().getTime();
		//console.log(&quot;FINITO&quot;);
		Benchmark.elapsed = Benchmark.finish - Benchmark.start;

		if(Benchmark.elapsed &gt; Benchmark.maxv)
				    Benchmark.maxv = Benchmark.elapsed;

		//labels
		if(Benchmark.labels.indexOf(benchmarkid) == -1)
			Benchmark.labels.push(benchmarkid);

		//data
		if(!Benchmark.data[serie])
			Benchmark.data[serie] = [];

		Benchmark.data[serie].push(Benchmark.elapsed);

		Benchmark.start = Benchmark.elapsed = Benchmark.finish = false;

		if(Benchmark.options.clean)
			Benchmark.clean(benchmarkid, serie);

	},
	each	:	function(test){//test){

		if(Benchmark.impossibile)
			return;

		//console.log(&quot;inizio i benchmark&quot;);

		for(var p = 1;p &lt;= Benchmark.maxc; p++){
			if(p % Benchmark.options.mod === 0){

				//console.log(&quot;benchmark &quot; + p);

				if(Benchmark.options.prepare)
					Benchmark.prepare(p);

					//lavora sulle serie
					for(arg in Benchmark.options.args) {

						Benchmark.serie(p, arg);
						//console.log(&quot;inizio la serie &quot; + arg + &quot; di &quot; + Benchmark.options.args[Benchmark.options.args.length -1]);

						Benchmark.append(p, arg);
						//console.log(&quot;appendo i figli &quot; + p);

						//esegue init()
						test(p, arg);

					}
				}
		}

	},
	prefix : function(nr, serie){
        return '#benchmark-dom' + nr +' &gt; #serie-'+ nr +'-'+ serie + '&gt; ';
    },
	init	:	function(options, nr, serie){

		options = jQuery.extend({
			test 	: function(){}
		}, options);

		var container = jQuery(this);
		var size = container.size();

        if(nr != size)
		  alert(&quot;Error. remove class from clone&quot;);

        Benchmark.start = new Date().getTime();
		return jQuery(this, container).each(
			function(z){
				var that = this;
				for(func in options.test){
					options.test[func](that, serie);//eseguita la funzione utente
				} 

				if(z == (size -1))
					Benchmark.stop(nr, serie);//nr è più sicuro
			}
		);

	}
};	

jQuery.fn.benchmark = Benchmark.init;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://maxb.net/blog/2008/05/21/benchmark-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

