Re: efficency question

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 03/12/04


Date: Fri, 12 Mar 2004 09:52:24 -0000

philipl@vistatec.ie <philipl@vistatec.ie> wrote:
> which is more efficient for looking up an element in an arraylist? An
> Arraylist.Contains? or Go throught it with a while or for loop?

I would imagine ArrayList.Contains is at least as efficient as anything
else, but more important is that it clearly states what you're after,
in a concise way. Always go for readability until you've got a reason
to believe that one piece of code is acting as a bottleneck.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • RE: reference counting and PyTuple_SetItem
    ... is truly the bottleneck, then it *may* be good to trade off maintainability ... But what you're doing in the C loop here is almost certainly ... at all -- it's buying you bugs, but I'm not sure it's buying you anything ...
    (comp.lang.python)
  • Re: bytes To Hex
    ... if i have a long loop ..i tend to do as little stack pops as i can ... which tends to bottleneck a lot more. ... paragon of readability. ... StringBuilder isn't a cure-all for string performance problems. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: test if socket is open only
    ... You need to quote some context of the message you are replying like I ... Check the group posting guidelines for instructions on doing ... for loop would cause the object to get destroyed right away closing the ...
    (comp.lang.perl.misc)
  • Re: exhaustive switch bound checking
    ... Artem Alimarine a écrit: ... this dispatch is done in a loop. ...
    (microsoft.public.vc.language)
  • Are structures really slower than numeric variables?
    ... I have the following "bottleneck" line in a loop, ... U is an Nx1 matrix, ... n.K is an Nx2 matrix, part of a large structure n ...
    (comp.soft-sys.matlab)