Inefficient code

Richmond Mathewson richmondmathewson at gmail.com
Fri Jun 26 16:42:17 EDT 2009


I just popped together a stack using your code and 2 versions of an image.

I made 2 buttons:

'COMPARE' contained your code
'COMPARE 2' contained your code with all references to your progress bar 
removed

I also introduced 2 extra flds; 'Stime' and 'Etime'

In both COMPARE and COMPARE 2 I inserted the following lines:

COMPARE

ON mouseUp
put the time into fld "Stime"
    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"
put the time into fld "Etime"
END mouseUp

COMPARE 2

ON mouseUp
put the time into fld "Stime"
    put 0 into c
    put the imagedata of image "Alpha" into idataalpha
    put the imagedata of image "Beta" into idatabeta
    REPEAT FOR each char myChar in idataalpha
        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"
put the time into fld "Etime"
END mouseUp

running the script in btn COMPARE 2 the script took less than a minute

running the script in btn COMPARE is taking so long while I am writing 
this that I
am getting cheesed-off and I am going to abort the thing.

The problem is your progress bar: get rid of it!





More information about the use-livecode mailing list