Setting Pixels - More answers to suggestions
Monte Goulding
monte at sweattechnologies.com
Thu Jan 30 00:45:01 EST 2003
>
> Hi I got 2.405 seconds with your script (Athlon 1600+ with 512MD DDR RAM)
>
> But the following script got 0.161 seconds:
>
> on mouseUp
> put the long seconds into tSeconds
> put empty into iData
> put binaryEncode("CCCC",0,0,255,0) into redPixel
> put the imageData of image 1 into tData
> delete char 1 to 1600 of tData
> repeat for 400
> put redPixel after iData
> end repeat
> set the imageData of image 1 to iData&tData
> put the long seconds-tSeconds
> end mouseUp
>
> The changes are:
> 1. I kept the image data in a separate variable until it was
> needed (tData)
> 2. I used repeat for (although in this instance id didn't save much time)
> 3. I put redPixel after rather than before. (Assuming the engine
> uses array
> structures to hold strings then putting the data before will mean
> that each
> array element will need to be pushed back).
>
Actually I just had a bit more of a play and found that the slow part of my
script was getting the imageData so I used a local variable and tested if it
was empty:
local tData
on mouseUp
put the long seconds into tSeconds
put empty into iData
put binaryEncode("CCCC",0,0,255,0) into redPixel
if tData = "" then
put the imageData of image 1 into tData
delete char 1 to 1600 of tData
end if
repeat for 400
put redPixel after iData
end repeat
set the imageData of image 1 to iData&tData
put the long seconds-tSeconds
end mouseUp
This makes it slightly slower on the first run: 0.168s but heaps faster on
subsequent runs 0.02s.
Have fun
Monte
More information about the use-livecode
mailing list