Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Chrtran in .NET
Message
From
09/11/2008 05:20:23
 
 
To
07/11/2008 14:13:32
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01360482
Message ID:
01360730
Views:
26
Hi,

Also interesting is the opcode difference between the two versions.
The faster, generic version actually has about 25% more code (mainly because of two occurences of 'constrained' - whatever that is)

>>Hi,
>>
>>>// 3 times slower
>>
>>Interesting. I expected the opposite....
>
>hi Viv,
>
>I was kind of surprised too. But when examining the ildasm I discovered 'box' three times.
>
>Think that explains it
>
>
>Console.WriteLine(" 2.Between(1,3) {0}", 2.BetweenX(1, 3));
>
>
>translates into
>
>  IL_0000:  ldstr      " 2.Between(1,3) {0}"
>  IL_0005:  ldc.i4.2
>  IL_0006:  box        [mscorlib]System.Int32
>  IL_000b:  ldc.i4.1
>  IL_000c:  box        [mscorlib]System.Int32
>  IL_0011:  ldc.i4.3
>  IL_0012:  box        [mscorlib]System.Int32
>  IL_0017:  call       bool GregoryAdam.Base.ExtensionMethods.ExtensionMethods::BetweenX(class [mscorlib]System.IComparable,
>                                                                                         class [mscorlib]System.IComparable,
>                                                                                         class [mscorlib]System.IComparable)
>
>
>
>#if true
>		// 3 times slower
>		public static bool BetweenX(this IComparable s, IComparable s1, IComparable s2)
>		{
>			return (s.CompareTo(s1) >= 0) && (s.CompareTo(s2) <= 0);
>		}
>#endif
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform