bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Relative speed of globbing and regex implementations


From: Bruno Haible
Subject: Re: Relative speed of globbing and regex implementations
Date: Tue, 11 Dec 2007 12:29:31 +0100
User-agent: KMail/1.5.4

James Youngman wrote:
> I notice that the gnulib fnmatch implementation is slower than the
> regex implementation, at least in those cases where a pattern can be
> compiled once and offered thousands of times.  Very roughly, I'd guess
> that the fnmatch implementation takes about 1.4x the time that the
> regex implementation takes.
> 
> Is there a known reason for this

There is at least the theoretical reason that the fnmatch implementation
must look at the pattern string each time; so it parses two strings in parallel,
whereas regex parses only the argument string each time.

> is it avoidable, or are we stuck with it?

It is inherent in fnmatch's API. If you change the API so as to allow
precompilation of a pattern with flags, I would expect similar speedups.

The API could look like this:

  typedef struct compiled_fnmatch;
  struct compiled_fnmatch * fnmatch_compile (const char *pattern, int flags);
  int fnmatch_exec (struct compiled_fnmatch *task, const char *string);
  void fnmatch_free (compiled_fnmatch *);

Bruno





reply via email to

[Prev in Thread] Current Thread [Next in Thread]