Hello Robert,
As for the ArrayList Contains method performance issue, I've just performed
some tests according to the code you provided and did encounter the same
behavior.(test through console applcations) The .net 1.1 version is about
14% faster than .net 2.0 version.
Comparing the generated IL code of the two version, the .net 2.0 one has
some additional instructions within the "contains" method of ArrayList in
the for loop. Here are the disassemby code I got:
==========VS 2003/.NET 1.1===========
IL_002e: call int32 [mscorlib]System.Environm ent::get_TickCo unt()
IL_0033: conv.i8
IL_0034: stloc.3
IL_0035: ldc.i4.0
IL_0036: stloc.s j
IL_0038: br.s IL_0049
IL_003a: ldloc.0
IL_003b: ldloc.2
IL_003c: callvirt instance bool
[mscorlib]System.Collecti ons.ArrayList:: Contains(object )
IL_0041: stloc.s objectInList
IL_0043: ldloc.s j
IL_0045: ldc.i4.1
IL_0046: add
IL_0047: stloc.s j
IL_0049: ldloc.s j
IL_004b: ldc.i4 0x457
IL_0050: blt.s IL_003a
IL_0052: ldstr "Contains took "
IL_0057: call int32 [mscorlib]System.Environm ent::get_TickCo unt()
========VS 2005/.NET 2.0============ =
int32 [mscorlib]System.Environm ent::get_TickCo unt()
IL_003c: conv.i8
IL_003d: stloc.3
IL_003e: ldc.i4.0
IL_003f: stloc.s j
IL_0041: br.s IL_0054
IL_0043: nop
IL_0044: ldloc.0
IL_0045: ldloc.2
IL_0046: callvirt instance bool
[mscorlib]System.Collecti ons.ArrayList:: Contains(object )
IL_004b: stloc.s objectInList
IL_004d: nop
IL_004e: ldloc.s j
IL_0050: ldc.i4.1
IL_0051: add
IL_0052: stloc.s j
IL_0054: ldloc.s j
IL_0056: ldc.i4 0x457
IL_005b: clt
IL_005d: stloc.s CS$4$0000
IL_005f: ldloc.s CS$4$0000
IL_0061: brtrue.s IL_0043
IL_0063: ldstr "Contains took "
IL_0068: call int32 [mscorlib]System.Environm ent::get_TickCo unt()
=============== =============== =============== ====
Based on the IL reference, these IL instructions are setting and loading
data into local variables and also do some judgement on the value.
Therefore, the 2.0 code actually sacrifice some performance to improve the
strength of such weak-type collection's methods. Also, based on my
experience, there're many such adjustment in the base class library of .net
framework which improve the code strength and type-safety with some
sacrifice on the performance. However, these performance hit is really
worthy from a higher layer perspective(suc h as from a whole application's
designing viewpoint).
Please feel free to let me know if there is any other information you
wonder.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.