471,627 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

a question about Generics.thanks a lot.

I saw the lecture video by Mr. Anders Hejlsberg on Tech-ed 2004
yesterday.There is a test on Generics performance,and I try it myself.
But,the result is not the same as the videw shows.the ArrayList of int is
even faster than the List<int> in my test,which are 140milliseconds 265
milliseconds seperately.I wonder why? Has the ArrayList class been modified
to handle valuetype more efficiently? or any other reason?
Thanks a lot for any help.
Feb 21 '06 #1
2 1273
Maybe your not reseting your timer. I show better perf with List<int> per
code below:

List<int> list = new List<int>();
ArrayList al = new ArrayList();
Stopwatch sw = new Stopwatch();
int loops = 1000000;
sw.Start();
for (int i = 0; i < loops; i++)
{
al.Add(i);
}
for (int i = 0; i < al.Count; i++)
{
int ii = (int)al[i];
}
Console.WriteLine("ArrayList:" + sw.ElapsedMilliseconds);

// List<int>
sw.Reset();
sw.Start();
for (int i = 0; i < loops; i++)
{
list.Add(i);
}
for (int i = 0; i < list.Count; i++)
{
int ii = list[i];
}
Console.WriteLine("List<int>:" + sw.ElapsedMilliseconds);

ArrayList:232
List<int>:28

ArrayList:209
List<int>:42

ArrayList:295
List<int>:28

ArrayList:329
List<int>:27

ArrayList:133
List<int>:63

--
William Stacey [MVP]

"han zhiyang" <ha********@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
|I saw the lecture video by Mr. Anders Hejlsberg on Tech-ed 2004
| yesterday.There is a test on Generics performance,and I try it myself.
| But,the result is not the same as the videw shows.the ArrayList of int is
| even faster than the List<int> in my test,which are 140milliseconds 265
| milliseconds seperately.I wonder why? Has the ArrayList class been
modified
| to handle valuetype more efficiently? or any other reason?
| Thanks a lot for any help.
Feb 21 '06 #2
Hi William,
Thank you very much.Yes,I 've tried your code (replace Stopwatch with
DateTime and TimeSpan correspondingly) and my code again,2 hours later from I
got my former result.I find all work as expected.However,I haven't modify my
code at all. I think this is more like a "cannot reentry" mistakes.I dare not
say that is a bug,maybe it's my machines' not frameworks'.It's a pity that I
hadn't printed the screen,otherwise,you can understand my puzzle dom.
PS.The ConsoleColor class on my computer also represents unstably.sometimes
I must close my cmd window and reopen it and run my program again to get the
right representation.

So Many little but bothering problems. Maybe I should reinstall my OS.

The great lecture by Anders Hejlsberg can be find on
http://msdn.microsoft.com/vcsharp/pr...321/DEV321.htm
or downloadable file
http://msdn.microsoft.com/vcsharp/pr...files/0MM0.wmv
and the demo occurs at 00:34:36 with topic Generics Performance lasting 5
minutes.
"William Stacey [MVP]" wrote:
Maybe your not reseting your timer. I show better perf with List<int> per
code below:

List<int> list = new List<int>();
ArrayList al = new ArrayList();
Stopwatch sw = new Stopwatch();
int loops = 1000000;
sw.Start();
for (int i = 0; i < loops; i++)
{
al.Add(i);
}
for (int i = 0; i < al.Count; i++)
{
int ii = (int)al[i];
}
Console.WriteLine("ArrayList:" + sw.ElapsedMilliseconds);

// List<int>
sw.Reset();
sw.Start();
for (int i = 0; i < loops; i++)
{
list.Add(i);
}
for (int i = 0; i < list.Count; i++)
{
int ii = list[i];
}
Console.WriteLine("List<int>:" + sw.ElapsedMilliseconds);

ArrayList:232
List<int>:28

ArrayList:209
List<int>:42

ArrayList:295
List<int>:28

ArrayList:329
List<int>:27

ArrayList:133
List<int>:63

--
William Stacey [MVP]

"han zhiyang" <ha********@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
|I saw the lecture video by Mr. Anders Hejlsberg on Tech-ed 2004
| yesterday.There is a test on Generics performance,and I try it myself.
| But,the result is not the same as the videw shows.the ArrayList of int is
| even faster than the List<int> in my test,which are 140milliseconds 265
| milliseconds seperately.I wonder why? Has the ArrayList class been
modified
| to handle valuetype more efficiently? or any other reason?
| Thanks a lot for any help.

Feb 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Wiktor Zychla | last post: by
11 posts views Thread by John Salerno | last post: by
1 post views Thread by Vladimir Shiryaev | last post: by
11 posts views Thread by hammad.awan_nospam | last post: by
3 posts views Thread by Showjumper | last post: by
7 posts views Thread by SpotNet | last post: by
6 posts views Thread by =?Utf-8?B?UXVhbiBOZ3V5ZW4=?= | last post: by
8 posts views Thread by Tony Johansson | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.