Adnan Hussain

I started off by trying to see the performance difference in the DataTable of the diff. versions (1.2 & 2.0) of the .NET FM, and ended up writing this post !

I created a console application with the following code:

static void Main(string[] args)

{

DateTime startTime = DateTime.Now;

int j = 10, k = 20;

for (decimal i = 0; i < 100000000; i++)

{

j = j*k;

}

TimeSpan ts = DateTime.Now - startTime;

System.Console.WriteLine(ts.TotalMilliseconds);

Console.ReadLine();

}

When compiled and run under VS.NET 2003 (.NET 1.1 framework) it took 9 - 10 secs depending on the machine i ran it from.

The Surprising thing:

When compiled and run under VS.NET 2005 (.NET 2.0 framework) it took 15 - 16 secs depending on the machine i ran it from.

WHY



Re: Common Language Runtime Strange performance issue !!! (.NET 2.0 much slower than 1.1)

nobugz

Why do you assume it should be just as fast Higher versions rarely are faster. I can easily see additional checks could have been added as .NET 1.1 problems surfaced. Hard to tell without digging through mscorlib.dll





Re: Common Language Runtime Strange performance issue !!! (.NET 2.0 much slower than 1.1)

Curt Nichols

Adnan Hussain wrote:

When compiled and run under VS.NET...

Don't run it from within VS. Open a new command line and run it from there; see what happens. You don't want to blame the CLR for what VS could be doing.





Re: Common Language Runtime Strange performance issue !!! (.NET 2.0 much slower than 1.1)

nobugz

I could reproduce the OP's measurements (13.0 vs 21.2 sec +/- 0.5).





Re: Common Language Runtime Strange performance issue !!! (.NET 2.0 much slower than 1.1)

Curt Nichols

Very interesting. I doní»t have either VS 2003 or a profiler installed here at home so I caní»t get some objective measurements. However, looking at the sample code one major oddity stands out--it uses a Decimal for the loop counter. I doubt that the JITter would mess up integer multiplication, but perhaps System.Decimal:: op_Increment (i++) changed in some way in the BCL

Changing the loop counter to an integral type would be an interesting comparison between VS2005 and VS2003. In Orcas B2 using an í«intí» loop counter is a hundred-fold faster than using the Decimal loop counter.





Re: Common Language Runtime Strange performance issue !!! (.NET 2.0 much slower than 1.1)

Feng Chen - MSFT

Hi Adnan,

Thank you for your valuable feedback. You may also submit it to the following site in the formal way: http://connect.microsoft.com/VisualStudio/.

Thanks!






Re: Common Language Runtime Strange performance issue !!! (.NET 2.0 much slower than 1.1)

Claudio Caldato [MSFT]

Newer releases can be actually faster!. If you compare 2.0 with 1.1 in a lot of scenarios you can see that performance is much better, for instance: warm startup, Generics, TryParse, Security, reflection, delegates and cross domain calls.

Anyway in this specific test the problem is that we changed the implementation of Decimal in .NET 2.0 to make it more compatible with the OS. Because of that some scenarios such as this microbenchmark show worse performance. The benchmark is not very interesting because the JIT optimized the For body so you are basically testing how fast a decimal can be incremented.

Thanks

Claudio





Re: Common Language Runtime Strange performance issue !!! (.NET 2.0 much slower than 1.1)

nobugz

Well, that was sort-of the point I guess. Either incrementing or multiplying is slower. How the slow-down would make the System.Decimal type more compatible with the OS is something you might want to explain. Please don't hesitate, we like a look into the specific kitchen.





Re: Common Language Runtime Strange performance issue !!! (.NET 2.0 much slower than 1.1)

Adnan Hussain

Hi Guys. Thanks a lots for your comments and feedback, but this is a secondary problem for me at hand, and i came across this issue by chance. The actual problem that i was facing was; that i had created a DataTable with 4 columns { int, string, decimal, datatime } respectively. I tried loading 0.5 Million rows of data into it and the code took twice the time in .NET 2.0 than in 1.1

static string[] ProductNames = {

"Phone",

"Laptop",

"Cigarettes",

"Pencil",

"Sharpner",

"Ruler",

"Box",

"Bottle",

"Tea",

"Coffee"

};

static TimeSpan CheckDataSetPerformanceForLoadRows(int rowCount)

{

DataSet ds = new DataSet();

DateTime startTime = new DateTime();

ds.Tables.Add("Product");

ds.Tables[0].Columns.Add(new DataColumn("ID", typeof(int)));

ds.Tables[0].Columns["ID"].Unique = true;

ds.Tables[0].Columns.Add(new DataColumn("ProductName", typeof(string)));

ds.Tables[0].Columns.Add(new DataColumn("Price", typeof(float)));

ds.Tables[0].Columns.Add(new DataColumn("DiscoveredOn", typeof(DateTime)));

startTime = DateTime.Now;

//Start loading the number of rows

Random rand = new Random();

for (int i = 0; i < rowCount; i++)

{

DataRow dr = ds.Tables[0].NewRow();

dr["ID"] = i;

dr["ProductName"] = ProductNames[i % 10];

dr["Price"] = i * rand.NextDouble();

dr["DiscoveredOn"] = DateTime.Now;

ds.Tables[0].Rows.Add(dr);

}

TimeSpan ts = DateTime.Now - startTime;

return (ts);

}





Re: Common Language Runtime Strange performance issue !!! (.NET 2.0 much slower than 1.1)

ReneeC

But what's your point




Re: Common Language Runtime Strange performance issue !!! (.NET 2.0 much slower than 1.1)

Adnan Hussain

Why is .NET 2.0 so much slower than 1.1 That is my point, I thought everything in 2.0 was more optimized and had less memory footprint, especially operations on DataSets and DataTables.



Re: Common Language Runtime Strange performance issue !!! (.NET 2.0 much slower than 1.1)

cbakopanos

microbenchmark

I could send you our application to test. It's much slower and we cannot explain why.