cross-platform compress & decompress

Mark Brownell gizmotron at earthlink.net
Wed Dec 3 03:04:14 EST 2003


On Tuesday, December 2, 2003, at 04:55  PM, Wouter wrote:

>>    ## result = -1448432724 2846534572 2846534572 294 664
>>
>
> Wow, you have a nice rig      :)

Mac X, G3 900 MHz, iBook, 14" screen. It keeps up with my IBM XP laptop 
2.1 GHz

That was tricky using a string of comma delimited numbers to then use
repeat with each item X in groovyString for looping. This added extra 
speed everywhere I tested it.

check this out from below:
   put halfblock1 && halfblock2 && halfblock3 && t1 && t2 && t3 && t4
   ## result = -1448432724 2846534572 2846534572 668 714 1011 607
   ## second = -1448432724 2846534572 2846534572 667 871 1034 607

this is faster:
     put binaryDecode("I",x,halfBlock2) into numConverted

this is slower:
     put charToNum(char 4 of x) + (charToNum(char 3 of x) * 256) + 
(charToNum(char 2 of x) * 65536) + (charToNum(char 1 of x) * 16777216) 
bitAnd 4294967295 into halfBlock3

=============================

this is faster:
     put ((xL bitAnd 4278190080) / 16777216) into zp
     put (zp bitAnd 255) into a
     put ((xL bitAnd 16711680) / 65536) into b
     put ((xL bitAnd 65280) / 256) into c
     put (xL bitAnd 255) into d

this is slower:
     put binaryDecode("CCCC",binaryEncode("I",xL),a,b,c,d) into 
numConverted


on mouseUp
   ## I added speed testing
   put num2char("169,170,171,172") into x
   ## N - decode signed four-byte integers in network order
   ## put binaryDecode("N",x,halfBlock1) into numConverted
   ## I - decode unsigned four-byte integers in host order
   put the milliseconds into zap1
   repeat with i = 1 to 100000
     put binaryDecode("I",x,halfBlock2) into numConverted
   end repeat
   put the milliseconds into zap2
   put zap2 - zap1 into t1
   ## my current solution
   put the milliseconds into zap6
   repeat with ii = 1 to 100000
     put charToNum(char 4 of x) + (charToNum(char 3 of x) * 256) + 
(charToNum(char 2 of x) * 65536) + (charToNum(char 1 of x) * 16777216) 
bitAnd 4294967295 into halfBlock3
   end repeat
   put the milliseconds into zap7
   put zap7 - zap6 into t2
   ----
   put halfBlock2 into xL
   put the milliseconds into zap3
   repeat with ii = 1 to 100000
     put binaryDecode("CCCC",binaryEncode("I",xL),a,b,c,d) into 
numConverted
     --put binaryEncode("N",xL) into fourChars
     --put binaryDecode("CCCC",fourChars,a,b,c,d) into numConverted
   end repeat
   put the milliseconds into zap4
   put zap4 - zap3 into t3
   ----
   put the milliseconds into zap5
   repeat with ii = 1 to 100000
     put ((xL bitAnd 4278190080) / 16777216) into zp
     put (zp bitAnd 255) into a
     put ((xL bitAnd 16711680) / 65536) into b
     put ((xL bitAnd 65280) / 256) into c
     put (xL bitAnd 255) into d
   end repeat
   put the milliseconds into zap6
   put zap6 - zap5 into t4
   put halfblock1 && halfblock2 && halfblock3 && t1 && t2 && t3 && t4
   ## result = -1448432724 2846534572 2846534572 668 714 1011 607
   ## second = -1448432724 2846534572 2846534572 667 871 1034 607
end mouseUp

function num2char sx
   repeat for each item i in sx
     put numtochar(i)  after z
   end repeat
   return z
end num2char

Mark



More information about the use-livecode mailing list