[Asterisk-Dev] FW: asterisk/doc CODING-GUIDELINES,1.4,1.5

Sergey Kuznetsov asterisk_biz at deeptown.org
Wed Jan 19 07:48:59 MST 2005


Even if it is empty string there will be performance downgrade in case 
if strlen not inline function.

because when call will be issued, CPU will flush internal pipeline and 
then will try get if from
cache. If it's not already in L1 cache it will be cache miss, and it 
will try to get it from L2 cache,
or even from memory, and that will be really slow. In this case you can 
easily lost few
tens of thousands on CPU cycles.

All the Best!
Sergey.


joachim wrote:

> If its a 0x00 it will stop yes, but if its not, it will continue, while
> its not necessary as we already know the string is not zero length.
>
> Which would mean that if the stringlength = 0, there will be no waste of
> cpu cycles, if its 1 char or more, it will waste cpu cycles.
>
> If the string is 255 chars, it will use up around 255 times more cpu
> cycles if you use the strlen.
>
>
> Zoa.
>
>
> Andrew Kohlsmith wrote:
>
>> On January 19, 2005 07:45 am, Jerris, Michael MI wrote:
>>
>>
>>> It would probably be more efficient to check just the first char of the
>>> string to see if it is 0 than to loop through the whole string to 
>>> see if
>>> it is > 0 length.
>>>
>>>
>>
>> But would strlen()'s loop not terminate on the first 0x00 char??  I 
>> mean a
>> couple dozen cycles here is not something a user's gonna notice, even 
>> in a
>> tight loop that is processing strings for Asterisk.
>>
>> Personally I feel this whole ast_strlen_zero macro (it better be a 
>> macro or at
>> least inline function!) is poor optimization -- does Asterisk really 
>> spend so
>> much time in strlen() that it was necessary?
>>
>> -A.
>> _______________________________________________
>> Asterisk-Dev mailing list
>> Asterisk-Dev at lists.digium.com
>> http://lists.digium.com/mailman/listinfo/asterisk-dev
>> To UNSUBSCRIBE or update options visit:
>>   http://lists.digium.com/mailman/listinfo/asterisk-dev
>>
>>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Asterisk-Dev mailing list
>Asterisk-Dev at lists.digium.com
>http://lists.digium.com/mailman/listinfo/asterisk-dev
>To UNSUBSCRIBE or update options visit:
>   http://lists.digium.com/mailman/listinfo/asterisk-dev
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-dev/attachments/20050119/452bad6d/attachment.htm


More information about the asterisk-dev mailing list