From owner-freebsd-hackers Fri Mar 29 15:46:14 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from scaup.prod.itd.earthlink.net (scaup.mail.pas.earthlink.net [207.217.120.49]) by hub.freebsd.org (Postfix) with ESMTP id D022B37B433; Fri, 29 Mar 2002 15:45:44 -0800 (PST) Received: from pool0156.cvx40-bradley.dialup.earthlink.net ([216.244.42.156] helo=mindspring.com) by scaup.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16r63m-0000U1-00; Fri, 29 Mar 2002 15:45:31 -0800 Message-ID: <3CA4FC84.BAB5B698@mindspring.com> Date: Fri, 29 Mar 2002 15:45:08 -0800 From: Terry Lambert X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Ilia Chipitsine Cc: questions@FreeBSD.ORG, hackers@FreeBSD.ORG Subject: Re: perfomance and regular expressions References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Ilia Chipitsine wrote: > I'm currently implementing a program which will run thousands and > thousands times. It uses regular expressions. > > something really simple, like > > regex_t re; > regcomp(&re,"^[0123456789abcdefghijklmnopqrstuvwxyz]{1,8}$", > REG_EXTENDED+REG_ICASE); > return(!regexec(&re,name,0,0,0)); > > so, questions are: > > 1) is it faster to "compile" regex once and load it from file every time > program starts ? > > 2) how to store in a file data of type "regex_t" ?? It's faster to make the program iterative, instead of redoing a fork-exec for each time you want the function, and then exiting. The startup time for the fork/exec and the rundown are going to take more time by several orders of magnitude than the regular expression compilation. That said, if you feel a moral imperative to save and load precompiled regular expressions. you can do it by serializing the structure contents to disk, and then reading them back in. See the XDR code for serilization/deserialization of structure contents. -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message