[comp.misc] Cost of strlen

webber@porthos.rutgers.edu (Bob Webber) (06/24/88)

In article <2314@rti.UUCP>, rcb@rti.UUCP (Random) writes:
< In article <Jun.22.22.48.57.1988.7380@aramis.rutgers.edu< webber@aramis.rutgers.edu (Bob Webber) writes:
< <...  Also it
< <is not clear that strlen would be heavily used (certainly it was never
< <a bottleneck in any of the compilers I wrote). 
<Actually the cost of strlen can be very high. On a VMS machine, the
<standard C library uses a LOCC (locate character) instruction to find
<the null and the end of a string. And the strcpy functions does the same thing
<and then issues a MOVC (move character) instruction with the returned length.
<This is great on a big VAX. However, on a MicroVAX this is awful since the
<instruction is not implemented in the hardware. I once ran a performance
<analysis on a simulator program we wrote here and it spent 25% of it's time
<in the strlen and strcpy functions. On a machine with the hardware instruction
<it spent only 6% of it's time in those routines.

The wonders of CISC.  Were they inline compiling the strlen refs?  It
is hard to imagine it paying to make the function call.  After all,
how long is the average string anyway?  And if they are so long, do
you really want to be copying them all over the place (rather than
building ptr structures to represent concatenations - maybe even
keeping lengths in the record along with the pointer)?

---- BOB (webber@athos.rutgers.edu ; rutgers!athos.rutgers.edu!webber)

rcb@rti.UUCP (Random) (06/24/88)

In article <Jun.23.21.53.37.1988.2344@porthos.rutgers.edu> webber@porthos.rutgers.edu (Bob Webber) writes:
>The wonders of CISC.  Were they inline compiling the strlen refs?  It
>is hard to imagine it paying to make the function call.  After all,
>how long is the average string anyway?  And if they are so long, do
>you really want to be copying them all over the place (rather than
>building ptr structures to represent concatenations - maybe even
>keep the lengths in the structure with the pointers

The concept of keeping the length and pointers in a structure (ala VMS
string descriptors) has been brought up. The code was originally developed
on Unix machines and a VMS 750 where this was not a problem. Now it
would require drastic changes to about 100,000 lines of code. Not a
plesant prospect.
-- 
					Randy Buckland (919)-541-7103
					Research Triangle Institute
					rcb@rti.rti.org [128.109.139.2]
					{decvax,ihnp4}!mcnc!rti!rcb