473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 14485
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.Length * 2" )

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

"ZenRhapsody" <no****@hotmail.com> wrote in message
news:eA**************@TK2MSFTNGP11.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
"ZenRhapsody" <no****@hotmail.com> wrote in message
news:eA**************@TK2MSFTNGP11.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:

"ZenRhapsody" <no****@hotmail.com> wrote in message
news:eA**************@TK2MSFTNGP11.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***@nickhounsome.me.uk> wrote in message
news:B1******************@fe3.news.blueyonder.co.u k...

"ZenRhapsody" <no****@hotmail.com> wrote in message
news:eA**************@TK2MSFTNGP11.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]

"ZenRhapsody" <no****@hotmail.com> wrote in message
news:uL**************@TK2MSFTNGP10.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*****@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.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:

"ZenRhapsody" <no****@hotmail.com> wrote in message
news:eA**************@TK2MSFTNGP11.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.machin AT dot.state.fl.us> wrote
in message news:OH***************@TK2MSFTNGP14.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***@nickhounsome.me.uk> wrote in message
news:B1******************@fe3.news.blueyonder.co.u k...

"ZenRhapsody" <no****@hotmail.com> wrote in message
news:eA**************@TK2MSFTNGP11.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
I'm sorry Nick, but I don't buy it.

There were no serious questions in your post. It was mainly an attack. I'm
not "avoiding standard classes", I am looking for comparitive information on
the standard Array vs. the standard (with 2.0) generic List. You assume
that in 80% of projects, performance is not an issue. I agree with you on
that, and think the number may even be higher. However, I wouldn't be
asking the question if my project was in that >80%.

In this stage of my development, there is NO COST WHATSOEVER in deciding to
use arrays vs. Lists. So, this is the perfect time to ask these questions.

You have no clue on my requirements. You should just keep your replies to
yourself. My former company made 30% of it's profits in the U.K. NowI know
why.


"Nick Hounsome" <nh***@nickhounsome.me.uk> wrote in message
news:lK*******************@fe1.news.blueyonder.co. uk...

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote in message news:OH***************@TK2MSFTNGP14.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***@nickhounsome.me.uk> wrote in message
news:B1******************@fe3.news.blueyonder.co.u k...

"ZenRhapsody" <no****@hotmail.com> wrote in message
news:eA**************@TK2MSFTNGP11.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 #11
You really know the answer already. Your not going to out perform the
strongly typed array primitive unless your grow logic in not so good.
ArrayList and generic lists just wrap arrays. The reason we use ArrayLists,
and List<T> is so you don't have to write that code yourself over and over.
The tests are simple, the choice depends on what your doing and if that is a
perf focus in your app. Because List are a general structure, there is some
slight overhead with If tests and such that you would not add using a
array[]. However, you need to get into the 100 million iteration range to
negate the fudge factor of +- 50ms. How many iterations will app have in a
day?

--
William Stacey [MVP]

"ZenRhapsody" <no****@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
| I'm sorry Nick, but I don't buy it.
|
| There were no serious questions in your post. It was mainly an attack.
I'm
| not "avoiding standard classes", I am looking for comparitive information
on
| the standard Array vs. the standard (with 2.0) generic List. You assume
| that in 80% of projects, performance is not an issue. I agree with you on
| that, and think the number may even be higher. However, I wouldn't be
| asking the question if my project was in that >80%.
|
| In this stage of my development, there is NO COST WHATSOEVER in deciding
to
| use arrays vs. Lists. So, this is the perfect time to ask these
questions.
|
| You have no clue on my requirements. You should just keep your replies to
| yourself. My former company made 30% of it's profits in the U.K. NowI
know
| why.
|
|
|
|
| "Nick Hounsome" <nh***@nickhounsome.me.uk> wrote in message
| news:lK*******************@fe1.news.blueyonder.co. uk...
| >
| > "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
| > wrote in message news:OH***************@TK2MSFTNGP14.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***@nickhounsome.me.uk> wrote in message
| >> news:B1******************@fe3.news.blueyonder.co.u k...
| >>>
| >>> "ZenRhapsody" <no****@hotmail.com> wrote in message
| >>> news:eA**************@TK2MSFTNGP11.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 #12

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

Similar topics

25
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...
12
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...
19
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...
48
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...
7
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...
13
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...
12
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...
7
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...
10
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.