Re: Boolean logic on strings?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jim Mack (jmack_at_mdxi.nospam.com)
Date: 11/16/04


Date: Mon, 15 Nov 2004 20:40:35 -0500

Larry Serflaten wrote:
> "Jim Mack" <jmack@mdxi.nospam.com> wrote
>> In addition to what others have suggested, that you do this one
>> character at a time, I would suggest that you first convert the
>> strings to byte arrays. Looping through the byte arrays should be
>> much faster than looping over the strings. Air code:
>
> That method has been shown to be slower than just looping through
> the string for a similar task. Something like 1.5 years ago we had a
> long discussion here on a method to do some string manipulations
> (I forget the exact task) and I was going to submit a byte array
> method, but by the time the strings are copied for use, and then
> copied back for output, the advantage of working with numbers is lost
> when compared with just using Mid to get at the individual characters.
>
> As always, however, actual performance testing should be done to
> verify which is the more performant method in this case....
>
> LFS

Larry -

I didn't time it, and on reflection I wouldn't do it exactly like that.
Instead:

BytX() = x$
BytY() = y$

for idx = 0 to ubound(BytX) Step 2
   BytX(idx) = ((BytX(idx) and 1) Or (BytY(idx) and 1)) + &h30
next

z$ = BytX()

This can avoid Unicode conversion because all the characters are low
Ascii.

This is the version I'd time. I have to believe that at some point
(length) the overhead of all the Mid$ would be a killer.

-- 
        Jim


Relevant Pages

  • Re: How to be a good programmer?
    ... > They're designed to take advantage of C's treatment of strings as arrays ... > of characters in order to wring out some additional speed. ...
    (comp.programming)
  • Re: Whats wrong with strcpy/strcat in this "C for Tcl" experiment?
    ... > are more like Tcl's strings than C. ... Just pointers to characters and arrays of characters. ...
    (comp.lang.tcl)
  • Re: Strings, Arrays, whatever
    ... Subject: Strings, Arrays, whatever ... "William M. Klein", EasyNews, UseNet made Easy! ... >up to only 32,767 characters. ...
    (comp.lang.pl1)
  • Re: Backwards File Dump
    ... > True, values in arrays, including characters in strings, display backwards. ...
    (comp.os.vms)
  • Re: Why R6RS is controversial
    ... the semantics of the language, ... behavior of grapheme-cluster characters under most linguistic ... as the strings grow longer. ... Normalization is hideously complicated, and may require many ...
    (comp.lang.scheme)