473,783 Members | 2,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

performance of Generic List?


Has anyone done any performance testing between new generic Lists and single
dimensional arrays?

I really like the code flexibility the List provides since I don't know how
many items I will have in the list. With my array approach, I have to
manage re-sizing the array myself.

So, is using List<myClass> x as fast as MyClass[] x ?
Feb 27 '06 #1
11 14521
Hello, ZenRhapsody!

List<myClass> x, internally will use myClass[] array;
So, the overhead of using List<T> is not big

However, you may not like List<T> memory allocation strategy ( allocation uses doubling algorithm - when enlarging list size it uses "this._items.Le ngth * 2" )

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Feb 27 '06 #2

"ZenRhapsod y" <no****@hotmail .com> wrote in message
news:eA******** ******@TK2MSFTN GP11.phx.gbl...

Has anyone done any performance testing between new generic Lists and
single dimensional arrays?

I really like the code flexibility the List provides since I don't know
how many items I will have in the list. With my array approach, I have to
manage re-sizing the array myself.

So, is using List<myClass> x as fast as MyClass[] x ?


Why do you care?

Either it is fast enough for your needs - in which case you should use it
because it makes the code easier to write and maintain - or it isn't - in
which case you are in big trouble and writing your own probably will not
give you enough to save you.

I assume that you are not required to properly test your code or you
wouldn't even ask this question.

Feb 27 '06 #3
Hi,

Take a look at
http://msmvps.com/blogs/jon.skeet/ar...reachperf.aspx it's
a comparision of the different ways to traverse a list.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"ZenRhapsod y" <no****@hotmail .com> wrote in message
news:eA******** ******@TK2MSFTN GP11.phx.gbl...

Has anyone done any performance testing between new generic Lists and
single dimensional arrays?

I really like the code flexibility the List provides since I don't know
how many items I will have in the list. With my array approach, I have to
manage re-sizing the array myself.

So, is using List<myClass> x as fast as MyClass[] x ?

Feb 27 '06 #4
To those of you with useful respones - thanks.

With small test cases, I have found today that the generic List to be
considerably
slower (> than 20%) IF you can get the initial size large enough - it's
comparable to faster if
many resizes are required. Of course, my tests are not optimized with
unsafe code blocks to limit subscript checking when manually resizing
arrays.

I'm still using C# express (company hasn't fully jumped to 2.0 yet),
and I know my debugging and optimization options are limited here. If I
could see the optimized assembly, I'd feel better with the results.

If any MSFT folks know where future optimizations are planned, that'd be
useful too.
Feb 27 '06 #5
Yo Nick, this is a professional forum for professionals who want to give each
other professional advice. Take your attitude elsewhere. You're wasting
people's precious time. Prick.

"Nick Hounsome" wrote:

"ZenRhapsod y" <no****@hotmail .com> wrote in message
news:eA******** ******@TK2MSFTN GP11.phx.gbl...

Has anyone done any performance testing between new generic Lists and
single dimensional arrays?

I really like the code flexibility the List provides since I don't know
how many items I will have in the list. With my array approach, I have to
manage re-sizing the array myself.

So, is using List<myClass> x as fast as MyClass[] x ?


Why do you care?

Either it is fast enough for your needs - in which case you should use it
because it makes the code easier to write and maintain - or it isn't - in
which case you are in big trouble and writing your own probably will not
give you enough to save you.

I assume that you are not required to properly test your code or you
wouldn't even ask this question.

Feb 27 '06 #6
Hi,

I agree with Michael, yours is not the best of the attitude, or at least
the tone of the answer does not seems nice to me.

You do have a point though, that sometimes the best code is not the fastest
, but sometimes it;s

OP: in addition to the other post I recommended you before read this
http://www.interact-sw.co.uk/iangblo...1/09/profiling , it's a post by
Ian Griffiths titled "Profilers and The Perils of Micro-Optimization"

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Nick Hounsome" <nh***@nickhoun some.me.uk> wrote in message
news:B1******** **********@fe3. news.blueyonder .co.uk...

"ZenRhapsod y" <no****@hotmail .com> wrote in message
news:eA******** ******@TK2MSFTN GP11.phx.gbl...

Has anyone done any performance testing between new generic Lists and
single dimensional arrays?

I really like the code flexibility the List provides since I don't know
how many items I will have in the list. With my array approach, I have
to manage re-sizing the array myself.

So, is using List<myClass> x as fast as MyClass[] x ?


Why do you care?

Either it is fast enough for your needs - in which case you should use it
because it makes the code easier to write and maintain - or it isn't - in
which case you are in big trouble and writing your own probably will not
give you enough to save you.

I assume that you are not required to properly test your code or you
wouldn't even ask this question.

Feb 27 '06 #7
It all depends on how your testing and if you size the list as big as the
test array from the beginning. If you look at the list, it resizes in
basically the same way you would do it yourself with an Array.Copy into a
larger array.

--
William Stacey [MVP]

"ZenRhapsod y" <no****@hotmail .com> wrote in message
news:uL******** ******@TK2MSFTN GP10.phx.gbl...
| To those of you with useful respones - thanks.
|
| With small test cases, I have found today that the generic List to be
| considerably
| slower (> than 20%) IF you can get the initial size large enough - it's
| comparable to faster if
| many resizes are required. Of course, my tests are not optimized with
| unsafe code blocks to limit subscript checking when manually resizing
| arrays.
|
| I'm still using C# express (company hasn't fully jumped to 2.0 yet),
| and I know my debugging and optimization options are limited here. If I
| could see the optimized assembly, I'd feel better with the results.
|
| If any MSFT folks know where future optimizations are planned, that'd be
| useful too.
|
|
Feb 27 '06 #8
Since your definition of a professional discussion seems to include personal
insults I can only assume that I am being too polite for you.

I professionally adise you not to swear at people.

"Michael" <Mi*****@discus sions.microsoft .com> wrote in message
news:1B******** *************** ***********@mic rosoft.com...
Yo Nick, this is a professional forum for professionals who want to give
each
other professional advice. Take your attitude elsewhere. You're wasting
people's precious time. Prick.

"Nick Hounsome" wrote:

"ZenRhapsod y" <no****@hotmail .com> wrote in message
news:eA******** ******@TK2MSFTN GP11.phx.gbl...
>
> Has anyone done any performance testing between new generic Lists and
> single dimensional arrays?
>
> I really like the code flexibility the List provides since I don't
> know
> how many items I will have in the list. With my array approach, I have
> to
> manage re-sizing the array myself.
>
> So, is using List<myClass> x as fast as MyClass[] x ?


Why do you care?

Either it is fast enough for your needs - in which case you should use it
because it makes the code easier to write and maintain - or it isn't - in
which case you are in big trouble and writing your own probably will not
give you enough to save you.

I assume that you are not required to properly test your code or you
wouldn't even ask this question.

Feb 28 '06 #9

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:OH******** *******@TK2MSFT NGP14.phx.gbl.. .
Hi,

I agree with Michael, yours is not the best of the attitude, or at least
the tone of the answer does not seems nice to me.
Do you mean my entirely serious and in no way abusive questioning of the OPs
motivation for looking to avoid standard classes for very low level
performance improvements?
You do have a point though, that sometimes the best code is not the
fastest , but sometimes it;s
Which is why you need to know the motivation and circumstances.

The best balance of performance and code complexity cannot be known without
having at least some idea what the actual requirements are.

In my experience in 80% of cases there is no need to make any performance
enhancement whatsoever. In 15% of cases the soultion is better algorithms at
a higher level and in the remaining 5% of cases the most cost effective
soloution is usually to require a more powerful computer to run on (It works
for Microsoft).
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Nick Hounsome" <nh***@nickhoun some.me.uk> wrote in message
news:B1******** **********@fe3. news.blueyonder .co.uk...

"ZenRhapsod y" <no****@hotmail .com> wrote in message
news:eA******** ******@TK2MSFTN GP11.phx.gbl...

Has anyone done any performance testing between new generic Lists and
single dimensional arrays?

I really like the code flexibility the List provides since I don't know
how many items I will have in the list. With my array approach, I have
to manage re-sizing the array myself.

So, is using List<myClass> x as fast as MyClass[] x ?


Why do you care?

Either it is fast enough for your needs - in which case you should use it
because it makes the code easier to write and maintain - or it isn't - in
which case you are in big trouble and writing your own probably will not
give you enough to save you.

I assume that you are not required to properly test your code or you
wouldn't even ask this question.


Feb 28 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
3491
by: Brian Patterson | last post by:
I have noticed in the book of words that hasattr works by calling getattr and raising an exception if no such attribute exists. If I need the value in any case, am I better off using getattr within a try statement myself, or is there some clever implementation enhancement which makes this a bad idea? i.e. should I prefer: if hasattr(self,"datum"): datum=getattr("datum") else: datum=None
12
3206
by: wxs | last post by:
Many times we have a bunch of enums we have from either different enums or the same enum that will have various numeric values assigned. Rarely will there be collisions in numbering between the enums. These enums you might imagine would be like OrderPrice=27, OrderQuantity=50, OrderSide=62. There may be a lot of these. So normally what we would have to do is store these in hash table so hashtable=value could be set with the value....
19
3155
by: Tom Jastrzebski | last post by:
Hello, I was just testing VB.Net on Framework.Net 2.0 performance when I run into the this problem. This trivial code attached below executed hundreds, if not thousand times faster in VB 6.0 than in .Net environment, under VS 2005 Beta 2. Does anyone have any idea whether this will be addressed in the final release? Thanks, Tomasz
48
4491
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a lot faster with both methods using .NET 1.1, that's why I am pretty sure its a (rather serious) bug. Below you can find C# test case that should allow you to reproduce this error, to run it you will need to put 2 data files into current directory...
7
2576
by: Michael D. Ober | last post by:
When calling Enqueue, the internal array may need to be reallocated. My question is by how much? In the old MFC array classes, you could tell MFC how many additional elements to add to the array when it needed to reallocate, which greatly boosted performance relative to adding 1 element at a time. Thanks, Mike Ober.
13
4607
by: atlaste | last post by:
Hi, I'm currently developing an application that uses a lot of computational power, disk access and memory caching (to be more exact: an information retrieval platform). In these kind of applications the last thing that remains is bare performance tuning. So for example, you can do an 'if then else' on a bit like a 'case/ switch', an 'if/then/else' and as a multiplication with a static buffer. Or, you can do sorting with an inline...
12
2452
by: Mark S. | last post by:
Hello, The app in question is lives on a Windows 2003 server with .NET 2.0 running IIS 6. The page of the app in question processes 2000 get requests a second during peak loads. The app uses a Static Object. In this object is a generic List<String>. For every page request this list is looped over only reading not writing each value.
7
4524
by: jehugaleahsa | last post by:
I wrote a simple method that allows me to pass a delegate to find a value in a list. I already had a set of methods for doing comparisons: less, greater, equal, equivalent, etc. However, find algorithms always compare the element in the list to a given value. In other words, I needed to bind one value for all the comparisons. I wrote a simple Bind1st method that looks like this: public delegate R Operation<R, T>(T value);
10
1895
by: colin | last post by:
Hi, I profile my code and find its spending a lot of time doing implicit conversions from similar structures. the conversions are mainly things like this class Point { implicit conversion to vector3; //this conversion just returns positon Vector3 position;
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.