Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Foreach vs AddRange
Message
De
11/08/2009 14:25:02
 
 
À
11/08/2009 14:19:16
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01417359
Message ID:
01417374
Vues:
68
>
>Hi,
>Don't know why the speed difference but have you tried pre-setting the capacity of list using the Capacity property (in both scenarios)?
>Best,
>Viv

Just did, Viv

There is no difference, and I would not have expected one since there are 6000000 iterations and the list must be expanded to its capacity after the first iteration


I was quite surprised to find that out

[Context]
I'm playing with streams, subclassed the stream to implement a base64 encoder/decoder

The problem with ToBase64Transform and FromBase64Transform is that you have to buffer the input, transform (pieces of )the input [ you do not know in advance whether to call TransformBlock or TransformFinalBlock ], and put the transformations on an outputbuffer
protected Queue<Byte> InBuffer = new Queue<byte>();
protected Queue<Byte> OutBuffer = new Queue<byte>();
The Read and Write of the stream work with arrays

So I tried - just for fun - how it would perform if I were to use List(byte)

I started testing with different array sizes - and found out that the List() is actually quite fast compared to the Queue

[ and the list is slower with many items compared to the queue ]
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform