<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Quattro interpreti ruby a confronto</title>
	<atom:link href="http://mastrodonato.info/index.php/2009/08/quattro-interpreti-ruby-a-confronto/feed/" rel="self" type="application/rss+xml" />
	<link>http://mastrodonato.info/index.php/2009/08/quattro-interpreti-ruby-a-confronto/</link>
	<description>Non c&#039;e&#039; prezzo per la miticita&#039;</description>
	<lastBuildDate>Mon, 07 Jun 2010 16:04:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Paolo</title>
		<link>http://mastrodonato.info/index.php/2009/08/quattro-interpreti-ruby-a-confronto/comment-page-1/#comment-6</link>
		<dc:creator>Paolo</dc:creator>
		<pubDate>Sat, 08 Aug 2009 09:07:16 +0000</pubDate>
		<guid isPermaLink="false">http://mastrodonato.info/?p=103#comment-6</guid>
		<description>Mi ha incuriosito la variazione di performance dei metodi di concatenazione di stringhe, che è un&#039;operazione che si fa di continuo. Mi sono chiesto allora quale fosse il metodo più veloce tra tutti.

Ho allora ripetuto il benchmark delle stringhe aggiungendo altri due metodi di concatenzione, ossia

%(#{stringa1} #{stringa2})

e

a = []; a &lt;&lt; stringa1; a &lt;&lt; stringa2; a.join(&quot; &quot;)

e facendo la prova anche con stringhe lunghe, da 500 caratteri l&#039;una.

Innanzitutto ho notato che ripetendo un po&#039; di volte il test &lt;&lt; #{} e %() risultano praticamente identici. Qualche volta vince uno e qualche volta vince un altro.

Per stringhe di un carattere il metodo dell&#039;array è un po&#039; più lento mentre per stringhe lunghe si pareggia agli altri. Per stringhe lunghe + diventa estremamente più lento di tutti gli altri metodi.

Questo è il risultato di un&#039;instanza del test, sperando che la formattazione sopravviva al post.

                           user     system      total        real
Concat 1.000.000:
+                      2.370000   0.130000   2.500000 (  2.532409)
&lt;&lt;                     2.310000   0.150000   2.460000 (  2.493730)
#{}                    2.410000   0.180000   2.590000 (  2.582961)
%()                    2.420000   0.150000   2.570000 (  2.588971)
Array                  4.250000   0.170000   4.420000 (  4.445646)
big +                 14.360000   0.240000  14.600000 ( 14.635854)
big #{}                6.210000   0.170000   6.380000 (  6.401311)
big %()                6.330000   0.180000   6.510000 (  6.522818)
big Array              6.500000   0.440000   6.940000 (  6.956503)

Portando le stringhe da concatenare da 500 a 1000 caratteri la concatenazione con Array rimane al livello degli altri. A 2000 inizia ad essere leggermente più veloce e a 4000 è decisamente più rapida.

big +                 86.840000   0.270000  87.110000 ( 87.336664)
big #{}               30.950000   0.190000  31.140000 ( 31.217629)
big %()               31.100000   0.270000  31.370000 ( 31.472801)
big Array             26.140000   6.470000  32.610000 ( 32.672105)

I test sono stati eseguiti su un Intel Core Duo 2 T7200 (dual core 2.0 GHz), ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux] 3.4 GB RAM.

Il codice in più è

  t1 = b.report(&quot;big +&quot;) do
    sa=&quot;%04000d&quot; % 1; sb=&quot;%04000d&quot; % 2; sc=&quot;%04000d&quot; % 3; 
    sd=&quot;%04000d&quot; % 4; se=&quot;%04000d&quot; % 5
    n.times { sa + &quot; &quot; + sb + &quot; &quot; + sc + &quot; &quot; + sd + &quot; &quot; + se; sb + &quot; &quot; + sc }
  end
  t1 += b.report(&quot;big \#\{\}&quot;) do
    sa=&quot;%04000d&quot; % 1; sb=&quot;%04000d&quot; % 2; sc=&quot;%04000d&quot; % 3; 
    sd=&quot;%04000d&quot; % 4; se=&quot;%04000d&quot; % 5
    n.times { &quot;#{sa} #{sb} #{sc} #{sd} #{se}&quot;; &quot;#{sb} #{sc}&quot; }
  end
  t1 += b.report(&quot;big \%\(\)&quot;) do
    sa=&quot;%04000d&quot; % 1; sb=&quot;%04000d&quot; % 2; sc=&quot;%04000d&quot; % 3; 
    sd=&quot;%04000d&quot; % 4; se=&quot;%04000d&quot; % 5
    n.times { %(#{sa} #{sb} #{sc} #{sd} #{se}); %(#{sb} #{sc}) }
  end
  t1 += b.report(&quot;big Array&quot;) do
    sa=&quot;%04000d&quot; % 1; sb=&quot;%04000d&quot; % 2; sc=&quot;%04000d&quot; % 3; 
    sd=&quot;%04000d&quot; % 4; se=&quot;%04000d&quot; % 5
    n.times { a = []; a &lt;&lt; sa; a &lt;&lt; sb; a &lt;&lt; sc; a &lt;&lt; sd; a &lt;&lt; se; a.join(&quot; &quot;);
              a = []; a &lt;&lt; sb; a &lt;&lt; sc; a.join(&quot; &quot;) }
  end

Il test big &lt;&lt; manca perché l&#039;operatore &lt;&lt; modifica il suo argomento di sinistra e non avevo voglia di includere dei literal da 4000 caratteri nel programma.</description>
		<content:encoded><![CDATA[<p>Mi ha incuriosito la variazione di performance dei metodi di concatenazione di stringhe, che è un&#8217;operazione che si fa di continuo. Mi sono chiesto allora quale fosse il metodo più veloce tra tutti.</p>
<p>Ho allora ripetuto il benchmark delle stringhe aggiungendo altri due metodi di concatenzione, ossia</p>
<p>%(#{stringa1} #{stringa2})</p>
<p>e</p>
<p>a = []; a &lt;&lt; stringa1; a &lt;&lt; stringa2; a.join(&quot; &quot;)</p>
<p>e facendo la prova anche con stringhe lunghe, da 500 caratteri l&#039;una.</p>
<p>Innanzitutto ho notato che ripetendo un po&#039; di volte il test &lt;&lt; #{} e %() risultano praticamente identici. Qualche volta vince uno e qualche volta vince un altro.</p>
<p>Per stringhe di un carattere il metodo dell&#039;array è un po&#039; più lento mentre per stringhe lunghe si pareggia agli altri. Per stringhe lunghe + diventa estremamente più lento di tutti gli altri metodi.</p>
<p>Questo è il risultato di un&#039;instanza del test, sperando che la formattazione sopravviva al post.</p>
<p>                           user     system      total        real<br />
Concat 1.000.000:<br />
+                      2.370000   0.130000   2.500000 (  2.532409)<br />
&lt;&lt;                     2.310000   0.150000   2.460000 (  2.493730)<br />
#{}                    2.410000   0.180000   2.590000 (  2.582961)<br />
%()                    2.420000   0.150000   2.570000 (  2.588971)<br />
Array                  4.250000   0.170000   4.420000 (  4.445646)<br />
big +                 14.360000   0.240000  14.600000 ( 14.635854)<br />
big #{}                6.210000   0.170000   6.380000 (  6.401311)<br />
big %()                6.330000   0.180000   6.510000 (  6.522818)<br />
big Array              6.500000   0.440000   6.940000 (  6.956503)</p>
<p>Portando le stringhe da concatenare da 500 a 1000 caratteri la concatenazione con Array rimane al livello degli altri. A 2000 inizia ad essere leggermente più veloce e a 4000 è decisamente più rapida.</p>
<p>big +                 86.840000   0.270000  87.110000 ( 87.336664)<br />
big #{}               30.950000   0.190000  31.140000 ( 31.217629)<br />
big %()               31.100000   0.270000  31.370000 ( 31.472801)<br />
big Array             26.140000   6.470000  32.610000 ( 32.672105)</p>
<p>I test sono stati eseguiti su un Intel Core Duo 2 T7200 (dual core 2.0 GHz), ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux] 3.4 GB RAM.</p>
<p>Il codice in più è</p>
<p>  t1 = b.report(&quot;big +&quot;) do<br />
    sa=&quot;%04000d&quot; % 1; sb=&quot;%04000d&quot; % 2; sc=&quot;%04000d&quot; % 3;<br />
    sd=&quot;%04000d&quot; % 4; se=&quot;%04000d&quot; % 5<br />
    n.times { sa + &quot; &quot; + sb + &quot; &quot; + sc + &quot; &quot; + sd + &quot; &quot; + se; sb + &quot; &quot; + sc }<br />
  end<br />
  t1 += b.report(&quot;big \#\{\}&quot;) do<br />
    sa=&quot;%04000d&quot; % 1; sb=&quot;%04000d&quot; % 2; sc=&quot;%04000d&quot; % 3;<br />
    sd=&quot;%04000d&quot; % 4; se=&quot;%04000d&quot; % 5<br />
    n.times { &quot;#{sa} #{sb} #{sc} #{sd} #{se}&quot;; &quot;#{sb} #{sc}&quot; }<br />
  end<br />
  t1 += b.report(&quot;big \%\(\)&quot;) do<br />
    sa=&quot;%04000d&quot; % 1; sb=&quot;%04000d&quot; % 2; sc=&quot;%04000d&quot; % 3;<br />
    sd=&quot;%04000d&quot; % 4; se=&quot;%04000d&quot; % 5<br />
    n.times { %(#{sa} #{sb} #{sc} #{sd} #{se}); %(#{sb} #{sc}) }<br />
  end<br />
  t1 += b.report(&quot;big Array&quot;) do<br />
    sa=&quot;%04000d&quot; % 1; sb=&quot;%04000d&quot; % 2; sc=&quot;%04000d&quot; % 3;<br />
    sd=&quot;%04000d&quot; % 4; se=&quot;%04000d&quot; % 5<br />
    n.times { a = []; a &lt;&lt; sa; a &lt;&lt; sb; a &lt;&lt; sc; a &lt;&lt; sd; a &lt;&lt; se; a.join(&quot; &quot;);<br />
              a = []; a &lt;&lt; sb; a &lt;&lt; sc; a.join(&quot; &quot;) }<br />
  end</p>
<p>Il test big &lt;&lt; manca perché l&#039;operatore &lt;&lt; modifica il suo argomento di sinistra e non avevo voglia di includere dei literal da 4000 caratteri nel programma.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
