Re: Most important QC of the year



Hi Roddy,

I don't think this will actually make *significant* improvements in
most cases. The odds on your strings having different lengths are
probably similar to the odds on the first characters being different,
so any real-world gain is likley to come from the 'tighter' code which
the fastcode guys write...

You raise an interesting point. The suggested LStrCmp is somewhat faster
than _LStrEqual when the string lengths are the same but the first character
differs (LStrEqual does an extra two memory reads and a stack push/pop in
this case). In all other cases _LStrEqual is significantly faster,
especially when the string lengths differ and the first character is the
same (like what could occur often when you're scanning a sorted list) - then
it just blows _LStrCmp out the water.

I did toy with the idea of adding the first character comparison to
_LStrEqual as well, but with the data I tested with it didn't seem to help.
The cost of setting up the comparison loop of _LStrCmp outweighs the cost of
the possible branch mispredict when comparing the first character, but in
_LStrEqual the loop setup is much cheaper so that is probably why _LStrEqual
didn't seem to benefit from it. I do reserve the right to go back and add
that check though ;-).

You might also wonder why it initially only compares the first character and
not the first two (long strings are zero terminated after all, so it should
be safe to read two characters): Unfortunately there are third party
libraries that generate non-nil pointer strings of 0 length. The rules
regarding this is somewhat vague, since the RTL functions never generate
such strings itself but it does function correctly with them (except for the
compiler magic "if AString = ' then" type checks which returns false for
such strings).

Regards,
Pierre


.



Relevant Pages

  • rs232 uart: testbench vs real world, and the missing first letter.
    ... My first cleanup was to at least reduce the strings to something that ... The side effect being that the first character of the string got ... so I've been working with the testbench and the actual development ... the real world is missing the first letter. ...
    (comp.arch.fpga)
  • Re: about STREQ
    ... >where strings being compared differ very often in their first character, ... The more you "know" about the nature of the strings, ...
    (comp.lang.c)
  • Re: perl help..
    ... > I have a loop that is running through a number of strings.. ... In some strings the first character is ... > punctuation or a number so a simple substr to pick up the first position ...
    (uk.comp.os.linux)
  • Re: My investigations into Godels Incompleteness Theorem
    ... long, whose first character is "0", whose second character ... Then it follows that there is a property P of strings such that ... use the correspondence to derive facts about one object from facts ... We set up a correspondence between sticks and real ...
    (sci.logic)
  • Re: about STREQ
    ... > where strings being compared differ very often in their first character, ... In purely random cases where 7-bit ascii is used, ... the first two characters of two strings will be the same is 1/128. ... Even in alpha strings the probability is 1/26 or even only 1/52. ...
    (comp.lang.c)