cody <pl*************************@gmx.de> wrote:
I think the jitter will always optimize s == "" to s.Length == 0
anyway.
I don't think so - for a start, it would have to add in a nullity test.
It's not terribly easy to pick out from a disassembly of optimised
native code, but I'm pretty sure it's *not* making that optimisation.
The following test program seems to bear that out. Note how many
iterations are needed to see a really significant difference though...
using System;
class Test
{
const int Iterations = 1000000000;
static void Main()
{
{
DateTime start = DateTime.Now;
int x = 0;
for (int i=0; i < Iterations; i++)
{
x += Bar("");
}
DateTime end = DateTime.Now;
Console.WriteLine ("{0} {1}", x, end-start);
}
{
DateTime start = DateTime.Now;
int x = 0;
for (int i=0; i < Iterations; i++)
{
x += Foo("");
}
DateTime end = DateTime.Now;
Console.WriteLine ("{0} {1}", x, end-start);
}
}
static int Foo (string x)
{
if (x=="")
{
return 1;
}
return 0;
}
static int Bar (string x)
{
if (x.Length==0)
{
return 1;
}
return 0;
}
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too