[Mono-list] Very fast growing of serialization time for big array

Andreas Färber andreas.faerber at web.de
Sat Feb 27 08:25:58 EST 2010


Hi,

Am 27.02.2010 um 13:21 schrieb Yury Serdyuk:

> I have tried to serialize a big array of floats ( more than 270  
> millions
> elements )
> and observed a very fast growing of serialization time.
[...]

In fact you're not just measuring the serialization time but also the  
time for the MemoryStream to grow and possible GCs triggered as a  
consequence.

> The code for testing was:
>
>> using System;
>> using System.IO;
>> using System.Runtime.Serialization;
>> using System.Runtime.Serialization.Formatters.Binary;
>>
>> public class BigSerializationTest {
>>
>> public static void Main ( String[] args ) {
>>
>>  int size = Convert.ToInt32 ( args [ 0 ] );
>>
>>  BinaryFormatter bf = new BinaryFormatter();
>>  MemoryStream    ms = new MemoryStream();

Try something like new MemoryStream (4 * size) for comparison.

>>  float[] array = new float [ size ];
>>
>>  for ( int i = 0; i < array.Length; i++)
>>   array [ i ] = 1.0f;
>>
>>  DateTime dt1 = DateTime.Now;
>>  bf.Serialize ( ms, array );
>>  DateTime dt2 = DateTime.Now;
>>
>>  Console.WriteLine ( "Serialization time = " + (dt2-dt1).TotalSeconds
>> + " secs." );
>>
>> }
>>
>>
>> }
>
> Do any have some thoughts about reasons of this problem and
> how to resolve it ?

Regards,

Andreas



More information about the Mono-list mailing list