<?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>Marco Mastrodonato &#187; Php</title>
	<atom:link href="http://mastrodonato.info/index.php/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://mastrodonato.info</link>
	<description>Non c&#039;e&#039; prezzo per la miticita&#039;</description>
	<lastBuildDate>Wed, 21 Sep 2011 07:12:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Files di grandi dimensioni su Windows Server 2008 R2 64Bit</title>
		<link>http://mastrodonato.info/index.php/2011/04/files-grandi-dimensioni-windows-server-2008-r2-64bit/</link>
		<comments>http://mastrodonato.info/index.php/2011/04/files-grandi-dimensioni-windows-server-2008-r2-64bit/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 14:57:57 +0000</pubDate>
		<dc:creator>Marco Mastrodonato</dc:creator>
				<category><![CDATA[IronRuby .NET]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[Prestazioni]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Benchmark]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Files]]></category>
		<category><![CDATA[IronRuby]]></category>
		<category><![CDATA[jRuby]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://mastrodonato.info/?p=665</guid>
		<description><![CDATA[Nel precedente articolo ho esaminato la semplice lettura e scrittura di tre files con dimensioni da 330Mb a 2,6Gb, su un normalissimo PC con Windows XP. Ora vediamo cosa cambia su un server virtuale, sistema produttivo che coinvolge un numero di aziende sempre più ampio. I linguaggi in esame sono i seguenti: Ruby 1.8.6 p383 [...]]]></description>
			<content:encoded><![CDATA[<p>Nel <a href="http://mastrodonato.info/index.php/2011/04/ruby-python-php-lua-comparazione-files-grandi-dimensioni/">precedente articolo</a> ho esaminato la semplice lettura e scrittura di tre files con dimensioni da 330Mb a 2,6Gb, su un normalissimo PC con Windows XP. Ora vediamo cosa cambia su un server virtuale, sistema produttivo che coinvolge un numero di aziende sempre più ampio.</p>
<p>I linguaggi in esame sono i seguenti:</p>
<p>Ruby 1.8.6 p383 (2009-08-04) [i386-mingw32]<br />
Ruby 1.8.7 p334 (2011-02-18) [i386-mingw32]<br />
Ruby 1.9.2 p180 (2011-02-18) [i386-mingw32]<br />
jruby 1.6.1 (ruby-1.8.7-p330) (2011-04-12) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_23) [Windows Server 2008 R2-amd64-java]<br />
IronRuby 1.1.3.0 (ruby-1.9.2) on .NET 4.0.30319.225<br />
Python 2.7.1 32bit<br />
Python 2.7.1 64bit<br />
Python 3.2.0 32bit<br />
Python 3.2.0 64bit<br />
Php 5.3.6 vc9 unsafe thread<br />
Lua 5.1.4 40<br />
C# 32bit on .NET 2.0.50727.4927<br />
C# 64bit on .NET 2.0.50727.4927<br />
C# 32bit on .NET 4.0.30319.1<br />
C# 64bit on .NET 4.0.30319.1</p>
<p>Solo python fornisce pacchetti di installazione x64 e ne ho approfittato per confrontarli con le versioni a 32 bit. Probabilmente le differenze si noteranno con operazioni matematiche rispetto la sezione IO ma questo apre la strada alla prossima comparazione.</p>
<p>La versione di ruby 1.8.6 è una mingw32 e non mswin32 come nel precedente test. <a href="http://www.ironruby.net/">IronRuby</a> invece è l&#8217;ultima 1.1.3 che abbraccia il supporto a ruby 1.9.2 e non 1.8.6 come la versione del precedente test con cui, comunque, condivide lo stesso framework .net e la stessa sezione IO.<br />
Questa volta ho anche aggiunto C# nella comparazione, ho compilato quattro versioni differenziando per piattaforma, x86 e x64, ed anche per framework, 3.5 e 4. Il framework .net 3.5 utilizza lo stesso <a href="http://it.wikipedia.org/wiki/Common_Language_Runtime">CLR</a> del 2.0. </p>
<p>Una nota di merito a IronRuby, il primo della classe che è persino davanti a C#, linguaggio compilato e con cui condivide molto. E&#8217; vero che questo test non richiede potenza computazionale particolarmente elevata ma è certamente un risultato curioso.</p>
<p>Un riepilogo anche sul consumo della memoria:</p>
<table>
<tr>
<td>Lua 5.1.4</td>
<td><b>0,7mb</b></td>
</tr>
<tr>
<td>Php 5.3.6</td>
<td>2,2mb</td>
</tr>
<tr>
<td>Python 2.7.1 32bit</td>
<td>2,5mb</td>
</tr>
<tr>
<td>Python 3.2.0 32bit</td>
<td>3,7mb</td>
</tr>
<tr>
<td>Python 2.7.1 64bit</td>
<td>4mb</td>
</tr>
<tr>
<td>Python 3.2.0 64bit</td>
<td>5,5mb</td>
</tr>
<tr>
<td>Ruby 1.9.2p180</td>
<td>4-6mb</td>
</tr>
<tr>
<td>Ruby 1.8.6p383</td>
<td>4-9mb</td>
</tr>
<tr>
<td>Ruby 1.8.7p334</td>
<td>4-9mb</td>
</tr>
<tr>
<td>C# 32bit on .NET 2.0.50727.4927</td>
<td>7mb</td>
</tr>
<tr>
<td>C# 32bit on .NET 4.0.30319.1</td>
<td>7mb</td>
</tr>
<tr>
<td>C# 64bit on .NET 2.0.50727.4927</td>
<td>9mb</td>
</tr>
<tr>
<td>C# 64bit on .NET 4.0.30319.1</td>
<td>9mb</td>
</tr>
<tr>
<td>IronRuby 1.1.3.0 on .NET 4.0.30319.225</td>
<td>11mb</td>
</tr>
<tr>
<td>jruby 1.6.1 (JVM 64-Bit Server 1.6.0_23)</td>
<td>jruby 1mb + java 200mb</td>
</tr>
</table>
<p><img src="http://i.imgur.com/np8SWl.jpg" alt="" title="2,6 Gb" /></p>
<p><img src="http://i.imgur.com/obUkdl.jpg" alt="" title="880 Mb" /></p>
<p><img src="http://i.imgur.com/FTWtFl.jpg" alt="" title="330 Mb" /></p>
<p><img src="http://i.imgur.com/Wv6f2l.jpg" alt="" title="Totale" /></p>
<p>Questo è il codice C# che ho compilato con Visual Studio 2010:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> Split
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">class</span> Program
    <span style="color: #008000;">&#123;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// To split a file into n output files</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;args&quot;&gt;Filename and records number to split&lt;/param&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> strInput <span style="color: #008000;">=</span> args<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> strOutput <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;out_{0:000}.txt&quot;</span><span style="color: #008000;">;</span>
            Int32 nrec_to_split <span style="color: #008000;">=</span> Convert<span style="color: #008000;">.</span><span style="color: #0000FF;">ToInt32</span><span style="color: #008000;">&#40;</span>args<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            DateTime t1 <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span>
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;C# {1} Started at {0:R}, please wait...&quot;</span>, t1, <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Environment</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Version</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
            StreamReader sr<span style="color: #008000;">;</span>
            StreamWriter sw <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            sr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamReader<span style="color: #008000;">&#40;</span>strInput<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            Int16 nsplit <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            Int64 nrec <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>sr<span style="color: #008000;">.</span><span style="color: #0000FF;">Peek</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>nrec <span style="color: #008000;">%</span> nrec_to_split <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #008000;">++</span>nsplit<span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sw <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    sw <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamWriter<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span>strOutput, nsplit<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                sw<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>sr<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">++</span>nrec<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Ended at {0:R}, please wait...&quot;</span>, DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Elapsed time {0}&quot;</span>, DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span> <span style="color: #008000;">-</span> t1<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mastrodonato.info/index.php/2011/04/files-grandi-dimensioni-windows-server-2008-r2-64bit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby, Python, Php e Lua in comparazione con files di grandi dimensioni</title>
		<link>http://mastrodonato.info/index.php/2011/04/ruby-python-php-lua-comparazione-files-grandi-dimensioni/</link>
		<comments>http://mastrodonato.info/index.php/2011/04/ruby-python-php-lua-comparazione-files-grandi-dimensioni/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 08:55:44 +0000</pubDate>
		<dc:creator>Marco Mastrodonato</dc:creator>
				<category><![CDATA[IronRuby .NET]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[Prestazioni]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Benchmark]]></category>
		<category><![CDATA[IronRuby]]></category>
		<category><![CDATA[jRuby]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://mastrodonato.info/?p=653</guid>
		<description><![CDATA[Vediamo come si comporta la sezione IO di alcuni tra i più popolari linguaggi script. L&#8217;esercizio consiste nel leggere sequenzialmente un grosso file di input e dividerlo in files più piccoli, in termini pratici, splittarlo. I linguaggi in esame sono: Ruby 1.8.6 p287 (2008-08-11) [i386-mswin32] Ruby 1.8.7 p334 (2011-02-18) [i386-mingw32] Ruby 1.9.2 p180 (2011-02-18) [i386-mingw32] [...]]]></description>
			<content:encoded><![CDATA[<p>Vediamo come si comporta la sezione IO di alcuni tra i più popolari linguaggi script. L&#8217;esercizio consiste nel leggere sequenzialmente un grosso file di input e dividerlo in files più piccoli, in termini pratici, splittarlo.</p>
<p>I linguaggi in esame sono:<br />
Ruby 1.8.6 p287 (2008-08-11) [i386-mswin32]<br />
Ruby 1.8.7 p334 (2011-02-18) [i386-mingw32]<br />
Ruby 1.9.2 p180  (2011-02-18) [i386-mingw32]<br />
jruby 1.5.1 (ruby 1.8.7 patch 249) (Java HotSpot(TM) Client VM 1.6.0_14) [x86-java]<br />
jruby 1.5.1 (ruby 1.8.7 patch 249) (Java HotSpot(TM) Client VM 1.6.0_24) [x86-java]<br />
jruby 1.6.1 (ruby-1.8.7-p330) (Java HotSpot(TM) Client VM 1.6.0_24) [Windows XP-x86-java]<br />
IronRuby 1.1.0.0 on .NET 4.0.30319.225<br />
Python 2.6.2<br />
Python 2.7.1<br />
Python 3.2.0<br />
Php 5.3.6 vc9 unsafe thread<br />
Lua 5.1.4 40</p>
<p>Iniziamo col creare i tre files di input necessari per il test:<br />
ruby new.rb input1.txt 185000 1799  => 330Mb<br />
ruby new.rb input2.txt 500000 1799  => 880Mb<br />
ruby new.rb input3.txt 1500000 1799 => 2,6Gb</p>
<p>Il test l&#8217;ho eseguito su un PC con cpu Intel E7300 Core2 Duo 2,66Ghz Ram 3,25Gb con Windows XP Professional 32bit, Hard Disk ST3250310AS Barracuda 7200.10 SATA 3.0Gb/s da 250Gb.</p>
<p>Prossimamente lo eseguirò anche su un Server Windows 2008 R2 64bit su VMWare Xeon X7460 Dual Core a 2,66Ghz e 2Gb di ram con dischi SCSI.</p>
<p>Prima e dopo aver creato i tre files di input ho deframmentato il disco. Se i tempi sono incostanti significa che il disco deve essere deframmentato o c&#8217;è qualcosa che rallenta il sistema come ad esempio l&#8217;antivirus che deve essere disabilitato.</p>
<p>Per ogni file ho eseguito sei elaborazioni e considerando le scarse prestazioni IO del sistema, ho scartato le tre peggiori. Naturalmente, prima di ogni test ho eliminato i files di output. </p>
<p>I grafici parlano da soli.<br />
L&#8217;unico commento che posso fare riguarda la versione 1.9.2 di ruby che ha evidenti problemi di IO e questi risultati non sono in linea con le performance generali di questo linguaggio che, come ho potuto rilevare da altri precedenti test, sono invece molto buone.</p>
<p><img src="http://i.imgur.com/48pyUl.jpg" alt="" title="2,6 Gb" /></p>
<p><img src="http://i.imgur.com/6xHd7l.jpg" alt="" title="880 Mb" /></p>
<p><img src="http://i.imgur.com/2leKpl.jpg" alt="" title="330 Mb" /></p>
<p><img src="http://i.imgur.com/Grrgjl.jpg" alt="" title="All three files" /></p>
<p>Questi sono gli script che ho scritto per l&#8217;occasione:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Written by Marco Mastrodonato on 19/04/2011</span>
<span style="color:#008000; font-style:italic;"># Script to split a file into n output files</span>
<span style="color:#008000; font-style:italic;"># Example:</span>
<span style="color:#008000; font-style:italic;"># ruby split.rb par1 par2</span>
<span style="color:#008000; font-style:italic;"># par1 =&gt; name [default =&gt; input1.txt]</span>
<span style="color:#008000; font-style:italic;"># par2 =&gt; record number that determines the number of output files [default =&gt; 1650]</span>
&nbsp;
strinput = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">'input1.txt'</span>
nrec_to_split = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span> : <span style="color:#006666;">1650</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>? strinput
	<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;File #{strinput} doesn't exists!&quot;</span> 
	<span style="color:#CC0066; font-weight:bold;">exit</span> <span style="color:#006666;">1</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
stroutput = <span style="color:#996600;">&quot;out_%03d.txt&quot;</span>
&nbsp;
t1= <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Ruby #{RUBY_VERSION} #{strinput} started at #{t1}, wait please...&quot;</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>strinput, <span style="color:#996600;">&quot;r&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
	nsplit = <span style="color:#006666;">0</span>
	nrec = <span style="color:#006666;">0</span>
	fileoutput = <span style="color:#0000FF; font-weight:bold;">nil</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">while</span> line = f.<span style="color:#CC0066; font-weight:bold;">gets</span>
		<span style="color:#9966CC; font-weight:bold;">if</span> nrec <span style="color:#006600; font-weight:bold;">%</span> nrec_to_split == <span style="color:#006666;">0</span>
			nsplit <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006666;">1</span>
			fileoutput.<span style="color:#9900CC;">close</span> <span style="color:#9966CC; font-weight:bold;">if</span> fileoutput
			fileoutput = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>stroutput <span style="color:#006600; font-weight:bold;">%</span> nsplit, <span style="color:#996600;">'w'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
		<span style="color:#9966CC; font-weight:bold;">end</span>
		fileoutput.<span style="color:#9900CC;">write</span> line
		nrec <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006666;">1</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	fileoutput.<span style="color:#9900CC;">close</span> <span style="color:#9966CC; font-weight:bold;">if</span> fileoutput
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Ended at #{Time.now}&quot;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Elapsed time #{Time.now - t1}&quot;</span>
<span style="color:#CC0066; font-weight:bold;">exit</span> <span style="color:#006666;">0</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># Written by Marco Mastrodonato on 19/04/2011</span>
<span style="color: #808080; font-style: italic;"># Script to split a file into n output files</span>
<span style="color: #808080; font-style: italic;"># Example:</span>
<span style="color: #808080; font-style: italic;"># python split.py par1 par2</span>
<span style="color: #808080; font-style: italic;"># par1 =&gt; name [default =&gt; input1.txt]</span>
<span style="color: #808080; font-style: italic;"># par2 =&gt; record number that determines the number of output files [default =&gt; 1650]</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">time</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>, gmtime, strftime
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">try</span>:
	strinput = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">except</span>:
	strinput = <span style="color: #483d8b;">'input1.txt'</span>
&nbsp;
stroutput = <span style="color: #483d8b;">&quot;out_%03d.txt&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">try</span>:
	nrec_to_split = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span>:
	nrec_to_split = <span style="color: #ff4500;">1650</span>
&nbsp;
t1 = <span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">version</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span>strftime<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Started at %a, %d %b %Y %H:%M:%S +0000, wait please...&quot;</span>, gmtime<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
nrec = <span style="color: #ff4500;">0</span>
nsplit = <span style="color: #ff4500;">0</span>
&nbsp;
<span style="color: #dc143c;">fileinput</span> = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>strinput, <span style="color: #483d8b;">&quot;r&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">fileinput</span>:
	<span style="color: #ff7700;font-weight:bold;">if</span> nrec <span style="color: #66cc66;">%</span> nrec_to_split == <span style="color: #ff4500;">0</span>:
		<span style="color: #ff7700;font-weight:bold;">try</span>:
			fileoutput.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">NameError</span>:
			fileoutput = <span style="color: #008000;">None</span>
		nsplit += <span style="color: #ff4500;">1</span>
		fileoutput = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>stroutput <span style="color: #66cc66;">%</span>nsplit , <span style="color: #483d8b;">&quot;w&quot;</span><span style="color: black;">&#41;</span>
	fileoutput.<span style="color: black;">write</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span>
	nrec += <span style="color: #ff4500;">1</span>    
fileoutput.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">fileinput</span>.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span>strftime<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Ended at %a, %d %b %Y %H:%M:%S +0000&quot;</span>, gmtime<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Elapsed time %f&quot;</span> <span style="color: #66cc66;">%</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> - t1<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Written by Marco Mastrodonato on 19/04/2011</span>
<span style="color: #666666; font-style: italic;">// Script to split a file into n output files</span>
<span style="color: #666666; font-style: italic;">// Example:</span>
<span style="color: #666666; font-style: italic;">// php split.php par1 par2</span>
<span style="color: #666666; font-style: italic;">// par1 =&gt; name [default =&gt; input1.txt]</span>
<span style="color: #666666; font-style: italic;">// par2 =&gt; record number that determines the number of output files [default =&gt; 1650]</span>
&nbsp;
<span style="color: #000088;">$strinput</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'input1.txt'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nrec_to_split</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">1650</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stroutput</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'out_%03d.txt'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$t1</span> <span style="color: #339933;">=</span> microtime_float<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Php &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">phpversion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; started at &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'D, d M Y H:i:s T'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;, wait please...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$nsplit</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nrec</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fileinput</span><span style="color: #339933;">=</span><span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$strinput</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileinput</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$nrec</span> <span style="color: #339933;">%</span> <span style="color: #000088;">$nrec_to_split</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #339933;">++</span><span style="color: #000088;">$nsplit</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileoutput</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileoutput</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$fileoutput</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stroutput</span><span style="color: #339933;">,</span> <span style="color: #000088;">$nsplit</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileinput</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileoutput</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #339933;">++</span><span style="color: #000088;">$nrec</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">fclose</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileinput</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Ended at &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'D, d M Y H:i:s T'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Elapsed time &quot;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span>microtime_float<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$t1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> microtime_float<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$usec</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sec</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span><span style="color: #000088;">$usec</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span><span style="color: #000088;">$sec</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">--[[
Written by Marco Mastrodonato on 19/04/2011
Script to split a file into n output files
Example:
lua split.lua par1 par2
par1 =&gt; name [default =&gt; input1.txt]
par2 =&gt; record number that determines the number of output files [default =&gt; 1650]
--]]</span>
strinput <span style="color: #66cc66;">=</span> arg <span style="color: #b1b100;">and</span> arg<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">or</span> <span style="color: #ff0000;">&quot;input1.txt&quot;</span>
stroutput <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;out_%03d.txt&quot;</span>
nrec_to_split <span style="color: #66cc66;">=</span> arg <span style="color: #b1b100;">and</span> arg<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">and</span> <span style="color: #b1b100;">tonumber</span><span style="color: #66cc66;">&#40;</span>arg<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #cc66cc;">1650</span>
&nbsp;
<span style="color: #b1b100;">local</span> t1 <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">os.clock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">_VERSION</span> .. <span style="color: #ff0000;">&quot; started at &quot;</span> .. <span style="color: #b1b100;">os.date</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;%a, %d %b %Y %H:%M:%S +0000&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
nsplit <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>
nrec <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>
<span style="color: #b1b100;">for</span> line <span style="color: #b1b100;">in</span> <span style="color: #b1b100;">io.lines</span><span style="color: #66cc66;">&#40;</span>strinput<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">do</span>
  <span style="color: #b1b100;">if</span> nrec <span style="color: #66cc66;">%</span> nrec_to_split <span style="color: #66cc66;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #b1b100;">then</span>
    <span style="color: #b1b100;">if</span> fileOut ~<span style="color: #66cc66;">=</span> <span style="color: #b1b100;">nil</span> <span style="color: #b1b100;">then</span> <span style="color: #b1b100;">io.close</span><span style="color: #66cc66;">&#40;</span>fileOut<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">end</span>
    nsplit <span style="color: #66cc66;">=</span> nsplit + <span style="color: #cc66cc;">1</span>
    fileOut <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">io.open</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string.format</span><span style="color: #66cc66;">&#40;</span>stroutput, nsplit<span style="color: #66cc66;">&#41;</span> , <span style="color: #ff0000;">'w'</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #b1b100;">end</span>
  fileOut:<span style="color: #b1b100;">write</span> <span style="color: #66cc66;">&#40;</span>line .. <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #66cc66;">&#41;</span>
  nrec <span style="color: #66cc66;">=</span> nrec + <span style="color: #cc66cc;">1</span>
<span style="color: #b1b100;">end</span>
&nbsp;
<span style="color: #b1b100;">io.close</span><span style="color: #66cc66;">&#40;</span>fileOut<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #b1b100;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Ended at &quot;</span> .. <span style="color: #b1b100;">os.date</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;%a, %d %b %Y %H:%M:%S +0000&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string.format</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Elapsed time: %.2f<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, <span style="color: #b1b100;">os.clock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> - t1<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Per creare i files ho usato questo semplice script ruby:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Example:</span>
<span style="color:#008000; font-style:italic;"># ruby new.rb [NOME] [LINES] [RECORD SIZE]</span>
&nbsp;
stroutput = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">'input1.txt'</span>
num = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span> : <span style="color:#006666;">185000</span>
size = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span> : <span style="color:#006666;">1799</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>? stroutput
	<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;File #{stroutput} already exists!&quot;</span> 
	<span style="color:#CC0066; font-weight:bold;">exit</span> <span style="color:#006666;">1</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
t1= <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Ruby #{RUBY_VERSION} #{stroutput} started at #{t1}, wait please...&quot;</span>
&nbsp;
line = <span style="color:#996600;">&quot;*&quot;</span> <span style="color:#006600; font-weight:bold;">*</span> size
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>stroutput, <span style="color:#996600;">&quot;w&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
	num.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;">do</span>
		f.<span style="color:#CC0066; font-weight:bold;">puts</span> line
	<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Ended at #{Time.now}&quot;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Elapsed time #{Time.now - t1}&quot;</span>
<span style="color:#CC0066; font-weight:bold;">exit</span> <span style="color:#006666;">0</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mastrodonato.info/index.php/2011/04/ruby-python-php-lua-comparazione-files-grandi-dimensioni/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Comparazione linguaggi script per la geometria frattale</title>
		<link>http://mastrodonato.info/index.php/2009/08/comparazione-linguaggi-script-per-la-geometria-frattale/</link>
		<comments>http://mastrodonato.info/index.php/2009/08/comparazione-linguaggi-script-per-la-geometria-frattale/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 23:38:24 +0000</pubDate>
		<dc:creator>Marco Mastrodonato</dc:creator>
				<category><![CDATA[IronRuby .NET]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Benchmark]]></category>
		<category><![CDATA[Frattali]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[Mandelbrot]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://mastrodonato.info/?p=209</guid>
		<description><![CDATA[In questo articolo metterò a confronto le ultime incarnazioni di ruby, con le ultime di python, groovy, php, lua, perl e anche java, per avere un metro di paragone con un linguaggio precompilato. Vedremo, infatti, come si comportano i linguaggi di script applicati alla geometria frattale, più precisamente un algoritmo della famiglia di Mandelbrot. Navigando, [...]]]></description>
			<content:encoded><![CDATA[<p>In questo articolo metterò a confronto le ultime incarnazioni di ruby, con le ultime di python, groovy, php, lua, perl e anche java, per avere un metro di paragone con un linguaggio precompilato. Vedremo, infatti, come si comportano i linguaggi di script applicati alla geometria frattale, più precisamente un algoritmo della famiglia di Mandelbrot.<br />
Navigando, ho trovato un <a href="http://www.timestretch.com/FractalBenchmark.html#4d9e0f15fc1b42420cf3f778c3cccad7">confronto</a> molto interessante ma un pò datato, risale a più di due anni fa. Da allora sono cambiate un pò di cose e ne ho approfittato per fare un aggiornamento anche se non includerò tutti quei linguaggi molti dei quali semi sconosciuti. Questa è l&#8217;occasione per mettere a confronto ruby e python anche nelle loro versioni java e .net, un intenzione che avevo già da un pò di tempo.</p>
<p>Usare un frattale come benchmark è oltretutto comodo: se un tentativo di ottimizzazione non va a buon fine se ne ha subito l&#8217;evidenza ed essendo disegnato in tempo reale, si riesce a percepire la velocità di esecuzione. Il frattale è disegnato in ascii anche perchè l&#8217;utilizzo di librerie esterne ne avrebbe drogato l&#8217;esito.</p>
<pre>
                                       *
                                       *
                                       *
                                       *
                                       *
                                      ***
                                     *****
                                     *****
                                      ***
                                       *
                                   *********
                                 *************
                                ***************
                             *********************
                             *********************
                              *******************
                              *******************
                              *******************
                              *******************
                            ***********************
                              *******************
                              *******************
                             *********************
                              *******************
                              *******************
                               *****************
                                ***************
                                 *************
                                   *********
                                       *
                                ***************
                            ***********************
                         * ************************* *
                         *****************************
                      * ******************************* *
                       *********************************
                      ***********************************
                    ***************************************
               *** ***************************************** ***
               *************************************************
                ***********************************************
                 *********************************************
                 *********************************************
                ***********************************************
                ***********************************************
              ***************************************************
               *************************************************
               *************************************************
              ***************************************************
              ***************************************************
         *    ***************************************************    *
       *****  ***************************************************  *****
       ****** *************************************************** ******
      ******* *************************************************** *******
    ***********************************************************************
    ********* *************************************************** *********
       ****** *************************************************** ******
       *****  ***************************************************  *****
              ***************************************************
              ***************************************************
              ***************************************************
              ***************************************************
               *************************************************
               *************************************************
              ***************************************************
                ***********************************************
                ***********************************************
                  *******************************************
                   *****************************************
                 *********************************************
                **** ****************** ****************** ****
                 ***  ****************   ****************  ***
                  *    **************     **************    *
                         ***********       ***********
                         **  *****           *****  **
                          *   *                 *   *
</pre>
<p>Questi sono i dati del sistema:<br />
Dell Inspiron 9400, Centrino Duo, T7200 @ 2Ghz 4Mb Cache L1, Ram 2Gb @ 667Mhz<br />
Windows XP pro SP3<br />
Java 6 update 15<br />
Microsoft .NET 3.5 SP1</p>
<p>Questi sono i risultati prestazionali ottenuti da una media di cinque rilevazioni catturate dopo qualche tentativo (non mi sono fidato dello startup delle VM):</p>
<pre>
Linguaggio      Tempo (in secondi)  n più lento di java
_____________________________________________________________
Java 6 update 15    0,153
Lua 5.1.4           0,815	           5x
Php 5.3.0           2,083	          14x
Python 2.6.2        2,269 	          15x
Python 3.1.1        1,566 	          10x
Jython 2.5.0        2,850 	          19x
Jruby 1.3.1         2,466 	          16x
Groovy 1.6.3        6,491 	          42x
Ruby 1.9.1 p129	    2,688 	          18x
Ruby 1.8.6 p368	    6,863 	          45x
Ruby 1.8.6 p111	    9,709 	          63x
IronRuby 0.9.0	    6,038 	          39x
IronPyhon 2.0.2     0,978 	           6x
Perl 5.10.0         2,722 	          18x
</pre>
<p>Questo è il grafico, naturalmente <strong>valori più bassi indicano una prestazione migliore</strong></p>
<p><img src="http://mastrodonato.info/wp-content/uploads/2009/08/chart2_537.png" alt="Chart" title="Chart" width="537" height="457" class="aligncenter size-full wp-image-262" /></p>
<p>Questi sono gli script usati per generare il frattale, andavano benissimo quelli di Erik Wrenholt, mi sono limitato a qualche semplice modifica per far funzionare python 3.1 o per migliorare lievemente la già ottima leggibilità in ruby e lua.</p>
<p><strong>Java</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// by Erik Wrenholt</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Bench1
<span style="color: #009900;">&#123;</span>  
	<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> BAILOUT <span style="color: #339933;">=</span> <span style="color: #cc66cc;">16</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> MAX_ITERATIONS <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> iterate<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span> x, <span style="color: #000066; font-weight: bold;">float</span> y<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">float</span> cr <span style="color: #339933;">=</span> y<span style="color: #339933;">-</span>0.5f<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">float</span> ci <span style="color: #339933;">=</span> x<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">float</span> zi <span style="color: #339933;">=</span> 0.0f<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">float</span> zr <span style="color: #339933;">=</span> 0.0f<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			i<span style="color: #339933;">++;</span>
			<span style="color: #000066; font-weight: bold;">float</span> temp <span style="color: #339933;">=</span> zr <span style="color: #339933;">*</span> zi<span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">float</span> zr2 <span style="color: #339933;">=</span> zr <span style="color: #339933;">*</span> zr<span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">float</span> zi2 <span style="color: #339933;">=</span> zi <span style="color: #339933;">*</span> zi<span style="color: #339933;">;</span>
			zr <span style="color: #339933;">=</span> zr2 <span style="color: #339933;">-</span> zi2 <span style="color: #339933;">+</span> cr<span style="color: #339933;">;</span>
			zi <span style="color: #339933;">=</span> temp <span style="color: #339933;">+</span> temp <span style="color: #339933;">+</span> ci<span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>zi2 <span style="color: #339933;">+</span> zr2 <span style="color: #339933;">&gt;</span> BAILOUT<span style="color: #009900;">&#41;</span>
				<span style="color: #000000; font-weight: bold;">return</span> i<span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&gt;</span> MAX_ITERATIONS<span style="color: #009900;">&#41;</span>
				<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Date</span> d1 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> x,y<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>y <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">39</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">39</span><span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">39</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">39</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>iterate<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">/</span>40.0f,y<span style="color: #339933;">/</span>40.0f<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> 
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;*&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">else</span>
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #003399;">Date</span> d2 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">long</span> diff <span style="color: #339933;">=</span> d2.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> d1.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Java Elapsed &quot;</span> <span style="color: #339933;">+</span> diff<span style="color: #339933;">/</span>1000.0f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Lua</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- By Erik Wrenholt</span>
&nbsp;
<span style="color: #b1b100;">local</span> BAILOUT <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">16</span>
<span style="color: #b1b100;">local</span> MAX_ITERATIONS <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1000</span>
&nbsp;
<span style="color: #b1b100;">function</span> iterate<span style="color: #66cc66;">&#40;</span>x,y<span style="color: #66cc66;">&#41;</span>
&nbsp;
  <span style="color: #b1b100;">local</span> cr <span style="color: #66cc66;">=</span> y-<span style="color: #cc66cc;">0.5</span>
  <span style="color: #b1b100;">local</span> ci <span style="color: #66cc66;">=</span> x
  <span style="color: #b1b100;">local</span> zi <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0.0</span>
  <span style="color: #b1b100;">local</span> zr <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0.0</span>
  <span style="color: #b1b100;">local</span> i <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>
&nbsp;
  <span style="color: #b1b100;">while</span> <span style="color: #cc66cc;">1</span> <span style="color: #b1b100;">do</span>
    i <span style="color: #66cc66;">=</span> i+<span style="color: #cc66cc;">1</span>
    <span style="color: #b1b100;">local</span> temp <span style="color: #66cc66;">=</span> zr <span style="color: #66cc66;">*</span> zi
    <span style="color: #b1b100;">local</span> zr2 <span style="color: #66cc66;">=</span> zr<span style="color: #66cc66;">*</span>zr
    <span style="color: #b1b100;">local</span> zi2 <span style="color: #66cc66;">=</span> zi<span style="color: #66cc66;">*</span>zi
    zr <span style="color: #66cc66;">=</span> zr2-zi2+cr
    zi <span style="color: #66cc66;">=</span> temp+temp+ci
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>zi2+zr2 <span style="color: #66cc66;">&gt;</span> BAILOUT<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
      <span style="color: #b1b100;">return</span> i
    <span style="color: #b1b100;">end</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>i <span style="color: #66cc66;">&gt;</span> MAX_ITERATIONS<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
      <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>
    <span style="color: #b1b100;">end</span>
  <span style="color: #b1b100;">end</span>
<span style="color: #b1b100;">end</span>
&nbsp;
<span style="color: #b1b100;">function</span> bench1<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #b1b100;">local</span> t <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">os.clock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #b1b100;">for</span> y <span style="color: #66cc66;">=</span> -<span style="color: #cc66cc;">39</span>, <span style="color: #cc66cc;">38</span> <span style="color: #b1b100;">do</span>
    <span style="color: #b1b100;">for</span> x <span style="color: #66cc66;">=</span> -<span style="color: #cc66cc;">39</span>, <span style="color: #cc66cc;">38</span> <span style="color: #b1b100;">do</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>iterate<span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">40.0</span>, y<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">40</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span> <span style="color: #b1b100;">io.write</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">io.write</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">end</span>
    <span style="color: #b1b100;">end</span>
    <span style="color: #b1b100;">io.write</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #b1b100;">end</span>
  <span style="color: #b1b100;">io.write</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string.format</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Time Elapsed %.3fn&quot;</span>, <span style="color: #b1b100;">os.clock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> - t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">end</span>
&nbsp;
bench1<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p><strong>Php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;BAILOUT&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MAX_ITERATIONS&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Bench1
<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> Bench1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$d1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">39</span><span style="color: #339933;">;</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">39</span><span style="color: #339933;">;</span> <span style="color: #000088;">$y</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">39</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">39</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">iterate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">/</span><span style="color:#800080;">40.0</span><span style="color: #339933;">,</span><span style="color: #000088;">$y</span><span style="color: #339933;">/</span><span style="color:#800080;">40.0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> 
					<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;*&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">else</span>
					<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$d2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$diff</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$d2</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$d1</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>PHP Elapsed <span style="color: #009933; font-weight: bold;">%0.3f</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$diff</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> iterate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">,</span><span style="color: #000088;">$y</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$cr</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$y</span><span style="color: #339933;">-</span><span style="color:#800080;">0.5</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ci</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$x</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$zi</span> <span style="color: #339933;">=</span> <span style="color:#800080;">0.0</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$zr</span> <span style="color: #339933;">=</span> <span style="color:#800080;">0.0</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
			<span style="color: #000088;">$temp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$zr</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$zi</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$zr2</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$zr</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$zr</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$zi2</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$zi</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$zi</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$zr</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$zr2</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$zi2</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$cr</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$zi</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$temp</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$temp</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$ci</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$zi2</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$zr2</span> <span style="color: #339933;">&gt;</span> BAILOUT<span style="color: #009900;">&#41;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&gt;</span> MAX_ITERATIONS<span style="color: #009900;">&#41;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">new</span> Bench1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>Python</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>, <span style="color: #dc143c;">time</span>
stdout = <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>
&nbsp;
BAILOUT = <span style="color: #ff4500;">16</span>
MAX_ITERATIONS = <span style="color: #ff4500;">1000</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Bench1:
  <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">'Rendering...'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> y <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>-<span style="color: #ff4500;">39</span>, <span style="color: #ff4500;">39</span><span style="color: black;">&#41;</span>:
      stdout.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'n'</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>-<span style="color: #ff4500;">39</span>, <span style="color: #ff4500;">39</span><span style="color: black;">&#41;</span>:
        i = <span style="color: #008000;">self</span>.<span style="color: black;">start</span><span style="color: black;">&#40;</span>x/<span style="color: #ff4500;">40.0</span>, y/<span style="color: #ff4500;">40.0</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span> i == <span style="color: #ff4500;">0</span>:
          stdout.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'*'</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
          stdout.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">' '</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">def</span> start<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, x, y<span style="color: black;">&#41;</span>:
    cr = y - <span style="color: #ff4500;">0.5</span>
    ci = x
    zi = zr = <span style="color: #ff4500;">0.0</span>
    i = <span style="color: #ff4500;">0</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
      i += <span style="color: #ff4500;">1</span>
      temp = zr <span style="color: #66cc66;">*</span> zi
      zr2 = zr <span style="color: #66cc66;">*</span> zr
      zi2 = zi <span style="color: #66cc66;">*</span> zi
      zr = zr2 - zi2 + cr
      zi = temp + temp + ci
&nbsp;
      <span style="color: #ff7700;font-weight:bold;">if</span> zi2 + zr2 <span style="color: #66cc66;">&gt;</span> BAILOUT:
        <span style="color: #ff7700;font-weight:bold;">return</span> i
      <span style="color: #ff7700;font-weight:bold;">if</span> i <span style="color: #66cc66;">&gt;</span> MAX_ITERATIONS:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span>
&nbsp;
t = <span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
Bench1<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>Python Elapsed %.3f'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> - t<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p><strong>Groovy</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//Created By Marco Mastrodonato 22/09/2009</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Bench1<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">int</span> BAILOUT <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">16</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">int</span> MAX_ITERATIONS <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1000</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">def</span> Bench1<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
        <span style="color: #993399;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Rendering...&quot;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span>y <span style="color: #b1b100;">in</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">39</span>..<span style="color: #cc66cc;">39</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
            <span style="color: #993399;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span>x <span style="color: #b1b100;">in</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">39</span>..<span style="color: #cc66cc;">39</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>iterate<span style="color: #66cc66;">&#40;</span>x/<span style="color: #cc66cc;">40.0</span>, y/<span style="color: #cc66cc;">40.0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
                    <span style="color: #993399;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
                    <span style="color: #993399;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#125;</span>
            <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">def</span> iterate<span style="color: #66cc66;">&#40;</span>x,y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
        <span style="color: #993333;">float</span> cr <span style="color: #66cc66;">=</span> y<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">0.5</span>
        <span style="color: #993333;">float</span> ci <span style="color: #66cc66;">=</span> x
        <span style="color: #993333;">float</span> zi <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0.0</span>
        <span style="color: #993333;">float</span> zr <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0.0</span>
        <span style="color: #000000; font-weight: bold;">def</span> i <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>
        <span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
            i <span style="color: #66cc66;">+=</span> <span style="color: #cc66cc;">1</span>
            <span style="color: #993333;">float</span> temp <span style="color: #66cc66;">=</span> zr <span style="color: #66cc66;">*</span> zi
            <span style="color: #993333;">float</span> zr2 <span style="color: #66cc66;">=</span> zr <span style="color: #66cc66;">*</span> zr
            <span style="color: #993333;">float</span> zi2 <span style="color: #66cc66;">=</span> zi <span style="color: #66cc66;">*</span> zi
            zr <span style="color: #66cc66;">=</span> zr2 <span style="color: #66cc66;">-</span> zi2 <span style="color: #66cc66;">+</span> cr
            zi <span style="color: #66cc66;">=</span> temp <span style="color: #66cc66;">+</span> temp <span style="color: #66cc66;">+</span> ci
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>zi2 <span style="color: #66cc66;">+</span> zr2 <span style="color: #66cc66;">&gt;</span> BAILOUT<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span> 
                <span style="color: #000000; font-weight: bold;">return</span> i
            <span style="color: #66cc66;">&#125;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>i <span style="color: #66cc66;">&gt;</span> MAX_ITERATIONS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span> 
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">0</span>
            <span style="color: #66cc66;">&#125;</span> 
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
time1 <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">time</span>
<span style="color: #000000; font-weight: bold;">new</span> Bench1<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
time2 <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">time</span>
<span style="color: #993333;">float</span> elapsed <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span>time2 <span style="color: #66cc66;">-</span> time1<span style="color: #66cc66;">&#41;</span>/<span style="color: #cc66cc;">1000</span>
<span style="color: #993399;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Groovy Elapsed ${elapsed}&quot;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p><strong>Ruby</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">BAILOUT = <span style="color:#006666;">16</span>
MAX_ITERATIONS = <span style="color:#006666;">1000</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> Bench1
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Rendering...&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">for</span> y <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">39</span>..<span style="color:#006666;">39</span>
      <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">for</span> x <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">39</span>..<span style="color:#006666;">39</span>
        i = iterate x<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">40.0</span>, y<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">40.0</span>
        <span style="color:#9966CC; font-weight:bold;">if</span> i == <span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">then</span> <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;*&quot;</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot; &quot;</span> <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> iterate<span style="color:#006600; font-weight:bold;">&#40;</span>x,y<span style="color:#006600; font-weight:bold;">&#41;</span>
    cr = y<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">0.5</span>
    ci = x
    zi = zr = <span style="color:#006666;">0.0</span>
    i = <span style="color:#006666;">0</span>
    <span style="color:#9966CC; font-weight:bold;">while</span> <span style="color:#0000FF; font-weight:bold;">true</span>
      i <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006666;">1</span>
      temp = zr <span style="color:#006600; font-weight:bold;">*</span> zi
      zr2 = zr <span style="color:#006600; font-weight:bold;">*</span> zr
      zi2 = zi <span style="color:#006600; font-weight:bold;">*</span> zi
      zr = zr2 <span style="color:#006600; font-weight:bold;">-</span> zi2 <span style="color:#006600; font-weight:bold;">+</span> cr
      zi = temp <span style="color:#006600; font-weight:bold;">+</span> temp <span style="color:#006600; font-weight:bold;">+</span> ci
      <span style="color:#0000FF; font-weight:bold;">return</span> i <span style="color:#9966CC; font-weight:bold;">if</span> zi2 <span style="color:#006600; font-weight:bold;">+</span> zr2 <span style="color:#006600; font-weight:bold;">&gt;</span> BAILOUT
      <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">if</span> i <span style="color:#006600; font-weight:bold;">&gt;</span> MAX_ITERATIONS
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
time = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
Bench1.<span style="color:#9900CC;">new</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>Ruby Elapsed %.3f&quot;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span> <span style="color:#006600; font-weight:bold;">-</span> time<span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p><strong>Perl</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Ported from C to Perl by Anders Bergh &lt;anders1@gmail.com&gt;</span>
&nbsp;
<span style="color: #0000ff;">$BAILOUT</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">16</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$MAX_ITERATIONS</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$begin</span> <span style="color: #339933;">=</span> <span style="color: #000066;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> mandelbrot <span style="color: #009900;">&#123;</span>
       <span style="color: #000066;">local</span> <span style="color: #0000ff;">$x</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$_</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
       <span style="color: #000066;">local</span> <span style="color: #0000ff;">$y</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$_</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #000066;">local</span> <span style="color: #0000ff;">$cr</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$y</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">0.5</span><span style="color: #339933;">;</span>
       <span style="color: #000066;">local</span> <span style="color: #0000ff;">$ci</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$x</span><span style="color: #339933;">;</span>
       <span style="color: #000066;">local</span> <span style="color: #0000ff;">$zi</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.0</span><span style="color: #339933;">;</span>
       <span style="color: #000066;">local</span> <span style="color: #0000ff;">$zr</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.0</span><span style="color: #339933;">;</span>
       <span style="color: #000066;">local</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
               <span style="color: #0000ff;">$i</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
               <span style="color: #000066;">local</span> <span style="color: #0000ff;">$temp</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$zr</span> <span style="color: #339933;">*</span> <span style="color: #0000ff;">$zi</span><span style="color: #339933;">;</span>
               <span style="color: #000066;">local</span> <span style="color: #0000ff;">$zr2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$zr</span> <span style="color: #339933;">*</span> <span style="color: #0000ff;">$zr</span><span style="color: #339933;">;</span>
               <span style="color: #000066;">local</span> <span style="color: #0000ff;">$zi2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$zi</span> <span style="color: #339933;">*</span> <span style="color: #0000ff;">$zi</span><span style="color: #339933;">;</span>
               <span style="color: #0000ff;">$zr</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$zr2</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">$zi2</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">$cr</span><span style="color: #339933;">;</span>
               <span style="color: #0000ff;">$zi</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$temp</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">$temp</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">$ci</span><span style="color: #339933;">;</span>
               <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$zi2</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">$zr2</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">$BAILOUT</span><span style="color: #009900;">&#41;</span>
               <span style="color: #009900;">&#123;</span>
                       <span style="color: #000066;">return</span> <span style="color: #0000ff;">$i</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
               <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$i</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">$MAX_ITERATIONS</span><span style="color: #009900;">&#41;</span>
               <span style="color: #009900;">&#123;</span>
                       <span style="color: #000066;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$y</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">39</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$y</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">39</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$y</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
       <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$x</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">39</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">39</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
               <span style="color: #0000ff;">$i</span> <span style="color: #339933;">=</span> mandelbrot<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$x</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">40.0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$y</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">40.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$i</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
               <span style="color: #009900;">&#123;</span>
                       <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
               <span style="color: #b1b100;">else</span>
               <span style="color: #009900;">&#123;</span>
                       <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$end</span> <span style="color: #339933;">=</span> <span style="color: #000066;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">$begin</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">printf</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Perl Elapsed %.3fn&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$end</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Commenti:</h3>
<p>La velocità di Lua è ormai nota, solamente 5 volte più lento rispetto al codice java compilato, il miglior risultato. La sua semplicità è la sua forza, forse è proprio questo che lo rende così veloce? E&#8217; stato adottato dalla Blizzard all&#8217;interno del gioco World of Warcraft e se l&#8217;hanno fatto loro un motivo ci sarà. Non è ad oggetti o meglio, nativamente non li supporta anche se c&#8217;è il progetto <a href="http://loop.luaforge.net/">LOOP</a> che lo estende a questo modello di programmazione.<br />
Php e Perl non hanno bisogno di commenti.<br />
Tra le versioni C di Ruby e Python è chiaramente avanti quest&#8217;ultimo. Il paragone equo sarebbe la Rb1.8.6 con la Py2.6.2 e la Rb1.9.1 con la Py3.1.1.<br />
La sfida tra le versioni che sfruttalo la Java VM: Groovy, Jython e JRuby, vede in vantaggio quest&#8217;ultimo. Groovy è molto indietro come prestazioni ma il dubbio più grosso che ho è: ma a chi è destinato? Come sintassi non è male ma ruby è ancora più scorrevole e poi ha quel rake che è tanto comodo per tante cose.<br />
Le versioni ruby e python per .Net vede incredibilmente avanti IronPython! Ma che gli hanno messo dentro, la dinamite? Sarà molto interessante esaminare il nuovo framework MVC di ASP.NET da poco arrivato alla versione 1 e che sarà incluso nel framework .Net 4, esistono progetti sia per IronRuby che per IronPython.<br />
Se questo articolo è risultato interessante, forse potrai trovare qualcos&#8217;altro tra gli annunci del mio sponsor, si trova nella colonna a destra, grazie!</p>
]]></content:encoded>
			<wfw:commentRss>http://mastrodonato.info/index.php/2009/08/comparazione-linguaggi-script-per-la-geometria-frattale/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

