[futurebasic] Re: [FB] FBtoC String speed in C

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2008 : Group Archive : Group : All Groups

From: Jay Reeve <jayreeve@...>
Date: Tue, 15 Apr 2008 00:42:36 -0500
On Apr 14, 2008, at 4:57 PM, Brian Stevens wrote:
> local fn Make_Hex_Line_Test$( a as Str255, bk as short )
> '~'1dim as Str255    hx
> dim as short     c, upperLimit
> if a[o] > 52 then a[0] = 52// set length byte to 52 or less
> defstr byte
> upperLimit = a[0]
> for c = 1 to upperLimit
> hx += hex$(a[c])
> if (( c mod bk ) == 0 ) then hx += " "
> next
> end fn = hx

Some of you know how much I enjoy a FB speed challenge. This is a  
little more code, may be impractical or obscure--and I have no idea  
what it will do in FBtoC--but if you're interested in speed, run this  
comparison in the profiler and see what you think. :-)

   e-e
   =J= a  y
    "

LOCAL FN MakeHexLine$( @charPtr as ptr, bk ) // <JR 20080415>
'~'1
dim as str255 hx
dim as ptr hexListPtr, @hp
dim inPos, theChar, outPos, last, spcCount
pstr$( hp ) = "0123456789ABCDEF"
hexListPtr = hp + 1
last = peek( charPtr )
if last > 52 then last = charPtr + 52 else last += charPtr
outPos = 0 : spcCount = 1

FOR charPtr = charPtr + 1 TO last
theChar = peek( charPtr )
outPos ++ : hx[ outPos ] = | hexListPtr + ( theChar >> 4 ) |
outPos ++ : hx[ outPos ] = | hexListPtr + ( theChar and 15 ) |
long if spcCount < bk
spcCount ++
xelse
outPos ++ : hx[ outPos ] = _" " : spcCount = 1
end if
NEXT inPos

hx[ 0 ] = outPos
END FN = HX

LOCAL:DIM HX$
local fn Make_Hex_Line_Test$( a as Str255, bk as short )
'~'1dim as Str255    hx
dim as short c, upperLimit
if a[0] > 52 then a[0] = 52// set length byte to 52 or less
defstr byte
hx[0] = 0
upperLimit = a[0]
for c = 1 to upperLimit
hx += hex$(a[c])
if (( c mod bk ) == 0 ) then hx += " "
next
end fn = hx

'~'1
window 1,,(0,0)-(750, 60)

dim d$, inStr$, x&
_testNum = 10000
inStr$ =  
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

for x = 1 to _testNum
d = fn MakeHexLine$( inStr$, 10 )
next
print d : print

for x = 1 to _testNum
d = fn Make_Hex_Line_Test$( inStr$, 10 )
next
print d