You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Christophe Jaillet <ch...@wanadoo.fr> on 2005/11/08 22:45:25 UTC
Speedup idea (by changing some strcasecmp into memcmp)
Hi,
in many places in apache, strings are compared using the following
construction :
if (0 == strcasecmp("XX", str)) {
...
}
else if (0 == strcasecmp("YY", str)) {
...
}
else if (0 == strcasecmp("ZZ", str)) {
...
}
else if (0 == strcasecmp("AA", str)) {
...
}
...
This cascading test could sometimes be optimized by doing the following :
* lowercase (or uppercase) a copy of the input string
* compare against this modified string using memcmp instead of strcasecmp
If the idea sounds interesting to you, I can provide a set of patchs that
implement this idea.
Christophe JAILLET
Re: Speedup idea (by changing some strcasecmp into memcmp)
Posted by Brian Candler <B....@pobox.com>.
On Tue, Nov 08, 2005 at 10:45:25PM +0100, Christophe Jaillet wrote:
> If the idea sounds interesting to you, I can provide a set of patchs that
> implement this idea.
Perhaps it would be better to start with profiling data. If you can
demonstrate via profiling that httpd spends a significant proportion of its
time in this area when actually running, I think that's a better approach
than just code inspection.
Experience has shown that in many cases intuition is wrong as to which bits
of code need optimising to improve overall performance.
Regards,
Brian.
Re: Speedup idea (by changing some strcasecmp into memcmp)
Posted by Ruediger Pluem <rp...@apache.org>.
On 11/08/2005 10:45 PM, Christophe Jaillet wrote:
> Hi,
>
> in many places in apache, strings are compared using the following
> construction :
> if (0 == strcasecmp("XX", str)) {
> ...
> }
> else if (0 == strcasecmp("YY", str)) {
> ...
> }
> else if (0 == strcasecmp("ZZ", str)) {
> ...
> }
> else if (0 == strcasecmp("AA", str)) {
> ...
> }
> ...
>
> This cascading test could sometimes be optimized by doing the following :
> * lowercase (or uppercase) a copy of the input string
> * compare against this modified string using memcmp instead of strcasecmp
>
> If the idea sounds interesting to you, I can provide a set of patchs that
I guess this depends on the situation and the surrounding code.
1. To actually win cycles the size of the string compared e.g. "AA" in the example
above and the number of strcasecmp calls need to be large enough. To be honest
I have no good number at all for "large enough".
2. Is the code that does a copy of this string called many times with the same pool
without a pool cleanup happening on this pool in the meantime? If yes, depending
on the number of calls and the size of the string this could waste at lot of memory.
In general I would favour to use strncmp over memcmp in these cases as I want to be
sure that comparison stops once one of the strings actually ends.
Regards
RĂ¼diger