Efficient STRing CoMPares?
Dave Schaumann
dave at cs.arizona.edu
Sun Mar 17 10:41:05 AEST 1991
In article <15486 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
|In article <1991Mar15.142821 at mars.mpr.ca> stone at mars.mpr.ca (Darren Stone) writes:
|>Does anyone know if there's a better (!?) way to compare
|>strings than with strcmp()?
|>I'm looking for any speed advantage I can get!
|
|#define StrEq( a, b ) (*(a) == *(b) && strcmp( a, b ) == 0) /* UNSAFE */
By "unsafe", I assume you mean it will likely crash on a NULL pointer.
I wouldn't be a bit suprised if strcmp() chokes on a NULL pointer, too.
But the main point I want to make is that this really buys you little unless
you are working under 2 conditions:
- strcmp() is not inlined
- function calls are expensive
I think you'll have to agree that any professional C compiler worth the name
would almost certainly inline *at least* the str???() functions; given an
environment where function calls are expensive.
Also, if you tend to compare equal successfully a lot, this will actually
be slower.
--
Dave Schaumann | dave at cs.arizona.edu | Short .sig's rule!
More information about the Comp.lang.c
mailing list