Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Foreach vs AddRange
Message
De
12/08/2009 02:57:43
 
 
À
11/08/2009 14:25:02
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01417359
Message ID:
01417470
Vues:
36
>>
>>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 ]

Just a general comment, without looking at the specifics of your tests whatsoever: sometimes when speed testing I've seen large drops in performance once a test overwhelms a CPU's L1 cache. If one of your tests is overwhelming the cache, and the other isn't, that could explain otherwise anomalous results.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform