Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 Mar 2002 15:45:08 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Ilia Chipitsine <ilia@cgu.chel.su>
Cc:        questions@FreeBSD.ORG, hackers@FreeBSD.ORG
Subject:   Re: perfomance and regular expressions
Message-ID:  <3CA4FC84.BAB5B698@mindspring.com>
References:  <Pine.BSF.4.10.10203292117510.1096-100000@jane.poka.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3CA4FC84.BAB5B698>