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 (2009-08-04) [i386-mingw32]
Ruby 1.8.7 p334 (2011-02-18) [i386-mingw32]
Ruby 1.9.2 p180 (2011-02-18) [i386-mingw32]
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]
IronRuby 1.1.3.0 (ruby-1.9.2) on .NET 4.0.30319.225
Python 2.7.1 32bit
Python 2.7.1 64bit
Python 3.2.0 32bit
Python 3.2.0 64bit
Php 5.3.6 vc9 unsafe thread
Lua 5.1.4 40
C# 32bit on .NET 2.0.50727.4927
C# 64bit on .NET 2.0.50727.4927
C# 32bit on .NET 4.0.30319.1
C# 64bit on .NET 4.0.30319.1
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.
La versione di ruby 1.8.6 è una mingw32 e non mswin32 come nel precedente test. IronRuby invece è l’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.
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 CLR del 2.0.
Una nota di merito a IronRuby, il primo della classe che è persino davanti a C#, linguaggio compilato e con cui condivide molto. E’ vero che questo test non richiede potenza computazionale particolarmente elevata ma è certamente un risultato curioso.
Un riepilogo anche sul consumo della memoria:
| Lua 5.1.4 | 0,7mb |
| Php 5.3.6 | 2,2mb |
| Python 2.7.1 32bit | 2,5mb |
| Python 3.2.0 32bit | 3,7mb |
| Python 2.7.1 64bit | 4mb |
| Python 3.2.0 64bit | 5,5mb |
| Ruby 1.9.2p180 | 4-6mb |
| Ruby 1.8.6p383 | 4-9mb |
| Ruby 1.8.7p334 | 4-9mb |
| C# 32bit on .NET 2.0.50727.4927 | 7mb |
| C# 32bit on .NET 4.0.30319.1 | 7mb |
| C# 64bit on .NET 2.0.50727.4927 | 9mb |
| C# 64bit on .NET 4.0.30319.1 | 9mb |
| IronRuby 1.1.3.0 on .NET 4.0.30319.225 | 11mb |
| jruby 1.6.1 (JVM 64-Bit Server 1.6.0_23) | jruby 1mb + java 200mb |




Questo è il codice C# che ho compilato con Visual Studio 2010:
using System; using System.IO; namespace Split { class Program { /// <summary> /// To split a file into n output files /// </summary> /// <param name="args">Filename and records number to split</param> static void Main(string[] args) { string strInput = args[0]; string strOutput = "out_{0:000}.txt"; Int32 nrec_to_split = Convert.ToInt32(args[1]); DateTime t1 = DateTime.Now; Console.WriteLine("C# {1} Started at {0:R}, please wait...", t1, System.Environment.Version); StreamReader sr; StreamWriter sw = null; sr = new StreamReader(strInput); Int16 nsplit = 0; Int64 nrec = 0; while (sr.Peek() >= 0) { if (nrec % nrec_to_split == 0) { ++nsplit; if (sw != null) sw.Close(); sw = new StreamWriter(String.Format(strOutput, nsplit)); } sw.WriteLine(sr.ReadLine()); ++nrec; } Console.WriteLine("Ended at {0:R}, please wait...", DateTime.Now); Console.WriteLine("Elapsed time {0}", DateTime.Now - t1); } } }




