[antlr-interest] Re: [antlr-dev] we can do push/pop error stuff for 4%

Sam Barnett-Cormack sdb at geekworld.co.uk
Sun May 28 03:45:59 PDT 2006


Prashant Deva wrote:
>>From what i read somewhere the Stack & Vector classes of Java are obsolete.
> It is recommended to use ArrayList or LinkedList instead.

Vector is not obsolete, it just isn't universal. But then again, neither
is ArrayList or LinkedList. All of them implement the List interface in
different ways, that lead to them being more appropriate in different
circumstances. For example, ArrayList and Vector implement storage in
the same way, but with different growing strategies. Also, one is
synchronised and the other isn't, so if you're not sharing across
threads using the synchronised one is a bit of a waste. LinkedList, on
the other hand, is implemented very much differently, and is cheaper to
use in many ways but expensive for random access.

Stack, on the other hands, isn't described as being bad anywhere
official that I've seen, but I think Ter has prooved that it is.

> On 5/28/06, *Terence Parr * <parrt at cs.usfca.edu
> <mailto:parrt at cs.usfca.edu>> wrote:
> 
>     Hi, so implemented my own stack and it's way faster.
> 
>     parse+lex 6261ms        using java.util.Stack
>     parse+lex 3710ms        using no push/pop at all
>     parse+lex 3860ms        using my own stack
> 
>     Given that lexing is like 1500ms, adding good error handling,
>     recovery only costs us about 150ms or 4% cpu speed.  I'll leave in,
>     but make it to use my stack.  Wow.  My stack costs 150ms vs 2551ms
>     for java.util.Stack.  What the hell is it doing?  ick.

Ter,

being crap, I imagine. Possibly being synchronised unnecessarily. How
did you implement your own? I've done it for my own use before on top of
LinkedList as an adaptor pattern, although the same code would work on
any List. LinkedList, however, seemed to be the best in most situations
I've seen provided it's implemented sanely.

Sam


More information about the antlr-interest mailing list