LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (May 2002, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 17 May 2002 21:38:51 -0700
Reply-To:     Dale McLerran <stringplayer_2@YAHOO.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Dale McLerran <stringplayer_2@YAHOO.COM>
Subject:      Re: Need advice on inefficient code
Comments: To: RICH0850 <rich0850@AOL.COM>
In-Reply-To:  <20020517193803.15945.00000243@mb-ft.aol.com>
Content-Type: text/plain; charset=us-ascii

Richard,

To add to my previous reply, let me suggest that you get rid entirely of the SUBSTR function and replace it with a bit of code which addresses each character in the string directly from its memory location. The functions which you need to invoke in order to perform this bit of magic are the ADDR and PEEKC functions. The ADDR function returns the memory location of the start of the string. The PEEKC function allows you to fetch the content at a memory address as a character variable. So, for the particular problem you gave, we would have

RTITL='The Quick Brown Fox Jumps Over The Lazy Dog'; RLN=LENGTH(RTITL); RLEN=0; start = addr(rtitl); end = start + rln - 1; DO I = start to end; rlen + input(peekc(i,1), pixels.); end;

Of course, you need to create the PIXEL informat as described in my previous post. Between replacing the SUBSTR function with the PEEKC function and replacing the conditional tests and assignment statements with a single assignment using an informat, this ought to be very efficient code. I hope that Hashman (aka Paul Dorfman) is proud to know that some of the lessons he has taught over the years have gotten through. I am sure that Paul could come up with something which is more efficient yet than using the input format to look up the length of each character. But for off-the-rack code, what I have presented above should be at or near maximal efficiency.

Dale

--- RICH0850 <rich0850@AOL.COM> wrote: > Dear Group: > > I've got some code that parses a string and returns the number of > pixels wide > the string is. I've determined how wide in pixels each character in > the > alphabet is (according to the font and size I'll be displaying in > the browser) > and then I run the string through this to get its total size in > pixels. > > Although the following code does the job it seems very inefficient to > me > (especially if I've got a lot of strings). Any ideas on how to do > this faster? > > RTITL='The Quick Brown Fox Jumps Over The Lazy Dog'; > RLN=LENGTH(RTITL); > RLEN=0; > DO I = 1 to RLN; > IF SUBSTR(RTITL,I,1) IN > ('I','i','l','.',' ') > THEN RLEN+2; > IF SUBSTR(RTITL,I,1) IN > ('/','j') > THEN RLEN+3; > IF SUBSTR(RTITL,I,1) IN > ('r') > THEN RLEN+4; > IF SUBSTR(RTITL,I,1) IN > ('a','c','E','F','f','J','t','x', > 'z','0','1','2','3','4','5','6','7', > '8','9') > THEN RLEN+5; > IF SUBSTR(RTITL,I,1) IN > ('B','b','D','d','e','g','H','h', > 'K','k','L','N','n','o','P','p','q','S', > 's','T','U','u','X','Y','Z','&') > THEN RLEN+6; > IF SUBSTR(RTITL,I,1) IN > ('A','C','G','O','Q','R','V','v','y') > THEN RLEN+7; > IF SUBSTR(RTITL,I,1) IN > ('M','w') > THEN RLEN+9; > IF SUBSTR(RTITL,I,1) IN > ('m') > THEN RLEN+10; > IF SUBSTR(RTITL,I,1) IN > ('W') > THEN RLEN+11; > END; > > Thanks in advance for any advice. > > --Richard

===== --------------------------------------- Dale McLerran Fred Hutchinson Cancer Research Center mailto: dmclerra@fhcrc.org Ph: (206) 667-2926 Fax: (206) 667-5977 ---------------------------------------

__________________________________________________ Do You Yahoo!? LAUNCH - Your Yahoo! Music Experience http://launch.yahoo.com


Back to: Top of message | Previous page | Main SAS-L page