From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: Any performance comparison/guide of/for Emacs regex? Date: Wed, 19 Jan 2011 08:27:56 +1100 Organization: Unlimited download news at news.astraweb.com Message-ID: <87wrm1vr4z.fsf@puma.rapttech.com.au> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1295386849 13731 80.91.229.12 (18 Jan 2011 21:40:49 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 18 Jan 2011 21:40:49 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 18 22:40:44 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PfJI9-0001nR-Lw for geh-help-gnu-emacs@m.gmane.org; Tue, 18 Jan 2011 22:40:41 +0100 Original-Received: from localhost ([127.0.0.1]:37927 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PfJI9-0007cV-51 for geh-help-gnu-emacs@m.gmane.org; Tue, 18 Jan 2011 16:40:41 -0500 Original-Path: usenet.stanford.edu!news.isc.org!news.glorb.com!news.astraweb.com!border2.newsrouter.astraweb.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:yW7XyibGbJtZthjOGwIEM6I+CpM= Original-Lines: 30 Original-NNTP-Posting-Host: 918e9891.news.astraweb.com Original-X-Trace: DXC=dj1WYV^?kWC48NP]Hm4n:I[b[7UeZ^KMIDlUO7@dPF@C Original-Xref: usenet.stanford.edu gnu.emacs.help:184395 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:78555 Archived-At: Oleksandr Gavenko writes: > Any performance comparison/guide of/for Emacs regex? > > Which construction use to get more performance? > > None that I'm aware of. With respect to performance, just follow the golden rule and make sure your regexp is anchored in some way. Many regexp implementations use a backtrackin form of regexp. If you don't anchor your regexp in some way, the amount of work it does in trying to find a match before giving up can grow very fast and can even give the impression the system is locked up. Common anchoring techniques include using ^ and $ to anchor your regexp to the start/end of a line and avoiding regexp with 'match everything' type wildcards at the start and end. If you know your regexp needs to match a specific sequence, include it and be as specific as possible. Use the correct meta characters such as ?, *, + etc. Take advantage of shy groups and non-greedy forms when they make sense. In general, be as precise as you can. Tim -- tcross (at) rapttech dot com dot au