performance of Generic List?

  • Thread starter Thread starter ZenRhapsody
  • Start date Start date
Z

ZenRhapsody

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 ?
 
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
 
ZenRhapsody said:
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.
 
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.
 
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 said:
ZenRhapsody said:
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.
 
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/iangblog/2005/11/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 said:
ZenRhapsody said:
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.
 
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]

| 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.
|
|
 
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 said:
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 said:
ZenRhapsody said:
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.
 
Ignacio Machin ( .NET/ C# MVP ) said:
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 said:
ZenRhapsody said:
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.
 
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 said:
Ignacio Machin ( .NET/ C# MVP ) said:
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 said:
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.
 
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]

| 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.
|
|
|
|
| | >
| > "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
| > wrote in message | >> 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
| >>
| >>
| >>
| >> | >>>
| >>> | >>>>
| >>>> 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.
| >>>
| >>>
| >>>
| >>
| >>
| >
| >
|
|
 
Back
Top