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