Inefficient code

J. Landman Gay jacque at hyperactivesw.com
Fri Jun 26 16:23:46 EDT 2009


Bert Shuler wrote:
> I have written this code a few different ways. Each seems to be equally 
> inefficient. I am attempting to compare to images, pixel by pixel, and 
> record the differences.
> 
> ON mouseUp pMouseBtnNo
>     put 0 into c
>     set the startvalue of scrollbar Progress to 0
>     set the endvalue of scrollbar Progress to the length of imagedata of 
> image "Alpha"
>     put the imagedata of image "Alpha" into idataalpha
>     put the imagedata of image "Beta" into idatabeta
>     REPEAT FOR each char myChar in idataalpha
>         set the thumbposition of scrollbar Progress to c
>         IF myChar is not  char (c) of idatabeta THEN
>             put c && char (c) of idatabeta & return after hAll
>         END IF
>         put c+1 into c
>     END repeat
>     put hAll into field "diff"
> END mouseUp
> 
> It takes many minutes to process a 200x200 image. I want this code to 
> eventually compare full screen-captures, so if there is any way to speed 
> it up, I am open for advice.

Take out the progress bar and then see how it does. Setting a progress 
indicator on every repeat often takes longer than running the entire 
rest of the handler.

If you do need a progress bar, only update it occasionally; for example, 
every few hundred iterations:

   if c mod 500 = 0 then set the thumbpos of sb "progress" to c

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list