Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Yesterday i saw in a post a guy said that built in Stack/Queue are 5x slower than a normally coded Stack/queue !
Is it true ?
If true then why Microsoft (C#.NET,VB.NET) or Oracle (JAVA) is giving such ADT ?
Which one you prefer ? Writing your own or using the built in ?

[I think most of the people prefer the built in as the code have been tested many times and is very very optimized]

share|improve this question

closed as not a real question by MichaelT, Kilian Foth, Bart van Ingen Schenau, gnat, Dynamic May 22 '13 at 11:27

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

I heard guys saying the strangest things. Is there a (well-executed - you propably wouldn't believe how much can be done wrong when benchmarking) benchmark on this topic? Otherwise, the question is pretty much moot. –  delnan Apr 16 '11 at 8:53
Measure! Only way to be certain... –  user1249 Apr 16 '11 at 8:59
Vector has been replaced with ArrayList in Java, use ArrayList instead. –  Mahmoud Hossam Apr 16 '11 at 9:11
@Mahmoud Hossam: It hasn't been replaced, they have different purposes. Vector is Synchronized (thread-safe), ArrayList is not. –  Brook Apr 16 '11 at 11:33
@Brook it's not "replaced", but Vector is considered as a "legacy" collection class, ArrayList is used in 99% of the cases. –  Mahmoud Hossam Apr 16 '11 at 12:19

3 Answers 3

Depends on what you mean, Microsoft would never release something that had obvious bad performance. He might have been talking about the new ConcurrentQueue and ConcurrentStack which is slower but that's because they can handle multithreaded scenarios.

Classes are always about making trade offs and in those cases Microsoft classes are "slow" it's usually because of some trade off. If there's no built in class that really fits and you can design a class tailored to your specific needs and trade offs that naturally that's going to perform the best

share|improve this answer
Microsoft has released many things that have obvious bad performance... ;) –  alternative Apr 16 '11 at 17:12
@mathepic: From the perspective of a language or primitive type? Do you have an example? –  Steve Evers Feb 20 '12 at 5:56
@SnOrfus That was over a year ago, but I would guess that I was referring to Microsoft products when I said that rather than any particular class... But alas, I don't recall haha –  alternative Feb 20 '12 at 18:54

In Java, Vector is thread-safe, while ArrayList is not. If the person who made the comment was building a non-thread safe List and comparing to Vector it's possible (still unlikely i think though) that could explain the performance difference.

In C# most collections are not thread safe, however 4.0 adds some new ones that are.

share|improve this answer

I think 5x is a lousy exaggeration. Of course the more lower level you go you will have higher speed. So Dot Net and Java strutures may be a bit slow but they they are more robust.

A simple example. A dot net array does bounds checking while a C/C++ array does not. The tradeoff is a slight drop in performance. In enterprise applications this tradeoff is worth the safety and robustness. In real-time applications the desire for performance needs will score over the need for robustness. Which is why you will use a lower level language. If you want something faster than a C-implemented array you will have to code in assembly language. Are you willing to take the effort ... especially if your application does not require a real-time performance? I'll bet not. Everything depends on your needs. You will use Dot Net for a desktop media player application, but not for a portable MP3 player.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.