Re: [Pyparsing] parsing with operatorPrecedence takes too much time
Brought to you by:
ptmcg
From: Ralf S. <sc...@gm...> - 2008-04-04 10:32:47
|
On Thu, Apr 3, 2008 at 12:15 AM, Paul McGuire <pt...@au...> wrote: > This performance problem has come up a couple of times in the past month. > For a start, you could try enabling packrat parsing - change your import > and > following lines to: > > > from pyparsing import (Word, Literal, CaselessLiteral, > Combine, Optional, nums, StringEnd, > operatorPrecedence, > opAssoc,ParserElement) > ParserElement.enablePackrat() > > > This will speed up your parser about 500X (not kidding!). > Paul, operatorPrecedence isn't working for me. I think something must be wrong, it's just much too slow. I've turned on packrat parsing. The current code can be viewed here: http://code.pediapress.com/hg/mwlib/file/ce563c294ad1/mwlib/e.py or downloaded here: http://code.pediapress.com/hg/mwlib/raw-file/ce563c294ad1/mwlib/e.py It reads expressions from stdin. Parsing something like: 5-(((63+459.67)/1.8)<100000)-(((63+459.67)/1.8)<10000)-(((63+459.67)/1.8)<1000)-(((63+459.67)/1.8)<100)-(((63+459.67)/1.8)<10) takes nearly 0.09 seconds. (i.e. one can only parse around 11 such expressions, which is unbeliavably slow for a 2.4 Ghz processor). The string representation of the expr parser element is huge: In [2]: len(str(e.expr)) Out[2]: 4317534 For my old parser this is length is 22076. What's going on? - Ralf |