[futurebasic] Re: [FB] Missing something

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2004 : Group Archive : Group : All Groups

From: Jay Reeve <jayreeve@...>
Date: Thu, 14 Oct 2004 18:19:16 -0500
On Thursday, October 14, 2004, at 03:48  PM, Edwards, Waverly wrote:

> Thanks Jay.
>
> Yes, I was trying to shift all characters one byte to the left.
> It was just a little, tiny, miniscule, almost sub-atomic mind 
> expanding experiment that didn't work out like I'd hoped.
> But, I learned something so that's a good thing.

I wouldn't say it didn't work out. I was surprised to find that your 
bit-shift algorithm, as I implemented it,  was usually faster (by a 
smidgen) than the block move, because it dealt with (effectively) 3 
bytes at a time, whereas blockmove AFAIK does just one at a time.

Your question got me wondering whether I could write a rotation fn that 
was faster than using blockmove, so I came up with this little demo. 
It's kind of fun even if you don't care about the code. After you watch 
it for a while, press cmd-Q, and if you've turned on the profiler and 
you can see the time comparisons for the 2 fns.

  e-e
  =J= a  y
   "

local fn strRotLftJAY(@p as ptr)
'Shift 4 bytes at a time
dim L, c
L = p.0`` - 1
c = p.1``
p ++
While L > 3
p.0& = p.1&
p += 4
L -= 4
wend
long if L and 2
p.0% = p.1%
p += 2
end if
if L and 1 then p.0`` = p.1`` : p ++
p.0`` = c
end fn

local fn strRotLftBLK(@p as ptr)
dim L,c
L = p.0``
c = p.1``
blockmove p + 2, p + 1, L
|p + L, c
end fn

dim s$,r
s$ = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 
7 8 9 "

do
for r = 1 to s[0] >> 1
fn strRotLftBLK(s)
print spc(10);s
fn strRotLftJAY(s)
print spc(10);s
next
handleevents
until 0


--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@...