Message race

General Macro Scheduler discussion

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Message race

Post by JRL » Mon Feb 05, 2007 11:20 pm

Hi All,
When I write a script that is going to run some background process for an extended period of time, I like to have the program display a message window informing the user that there is indeed a need to wait. It's very disconcerting watching a motionless screen minute after minute wondering if the computer is locked up. One trick is to display process information in a message window. This way the screen is active and there is no doubt that the program is proceeding as planned. For example if the program is copying a large number of files, a message window might display each file's name as it is being copied.

This thread spoke of multiple ways to display changing information in a single message box. It got me wondering about how much processing time was being spent on display of information for the comfort of the user. To help myself understand the differences, I wrote this script.

The only processing that takes place is upward incrementing of a variable and the painting and repainting of a window to display that variable. I looked into three ways of display.

--A standard Macro Scheduler message box that is redisplayed with each cycle of the program loop.

--A standard Macro Scheduler message box that is static and only the text is redisplayed each cycle using SetControlText.

--And a Macro Scheduler dialog box that uses ResetDialogAction to refresh its text each cycle.

I also wanted to see the affect that building a list has on the processing time. There is a radiobox that allows you to build and display a list of numbers, only display the current number, or display nothing (a blank message box).

There is an edit box to choose the number of cycles and an edit box to choose the wait time in each cycle. Be sure to test a wait time of 0.

I am not putting this into a code window so be sure to eliminate any trailing spaces after you copy and paste into your editor. The script follows and is green.

Hope someone finds this useful,
Dick

Edit-1, added a choice for label or memo as a display format when dialog is selected.


Let>script1=%TEMP_DIR%Message.scp

Dialog>Dialog1
Caption=Message Box Test Setup
Width=350
Height=323
Top=CENTER
Left=CENTER
Edit=msEdit1,128,40,81,1000
Edit=msEdit2,128,80,81,0.01
RadioGroup=msRadioGroup1,Message Type,16,120,185,65,Normal Message box%CRLF%SetControlText in Message box%CRLF%Dialog Box,0
RadioGroup=msRadioGroup2,List Type,216,120,113,65,Scrolling List%CRLF%One Line (No List)%CRLF%Blank,0
RadioGroup=msRadioGroup3,Dialog display,16,192,185,49,Text as a label%CRLF%Text in a memo field,0
Button=OK,16,264,75,25,3
Button=Cancel,248,264,75,25,2
Label=How many cycles to run the message test?,72,24
Label=How Many seconds per cycle?,96,64
RadioGroup=msRadioGroup3,Dialog display,16,192,185,49,Text as a label%CRLF%Text in a memo field,-1
Default=OK
EndDialog>Dialog1

Label>start
IfFileExists>%script1%
DeleteFile>%script1%
EndIf
Show>dialog1,r1
ResetDialogAction>dialog1
CloseDialog>dialog1
If>%dialog1.msedit2%=
Let>dwell=0
Else
Let>dwell=%dialog1.msedit2%
EndIf
If>r1=2,quit
Let>StopWrite=0

WriteLn>%script1%,wres,Let>arel=RL
WriteLn>%script1%,wres,Let>percent=%
WriteLn>%script1%,wres,GetTime>starttime
WriteLn>%script1%,wres,Let>k=0
WriteLn>%script1%,wres,Let>text=%dialog1.msedit1% cycles at %dwell% seconds per cycle
If>%dialog1.msradiogroup1.itemindex%=2,DialogMessage
If>StopWrite=1,BuildComplete
WriteLn>%script1%,wres,LET>MSG_YPOS=200
WriteLn>%script1%,wres,Let>MSG_HEIGHT=200
WriteLn>%script1%,wres,message>%text%
WriteLn>%script1%,wres,Repeat>k
WriteLn>%script1%,wres,IfWindowOpen>Macro Scheduler Message*
WriteLn>%script1%,wres, Let>k=k+1
If>%dialog1.msradiogroup2.itemindex%=0,ScrollingList
If>%dialog1.msradiogroup2.itemindex%=1,OneLineList
If>%dialog1.msradiogroup2.itemindex%=2,Blank
If>%dialog1.msradiogroup1.itemindex%=0,NormalMessage
If>%dialog1.msradiogroup1.itemindex%=1,SetTextMessage
WriteLn>%script1%,wres, Wait>%dwell%
WriteLn>%script1%,wres,Else
WriteLn>%script1%,wres, Goto>end
WriteLn>%script1%,wres,EndIf
WriteLn>%script1%,wres,Until>k,%dialog1.msedit1%
WriteLn>%script1%,wres,Gettime>endtime
WriteLn>%script1%,wres,Separate>starttime,%SPACE%,mer
WriteLn>%script1%,wres,Separate>mer_1,:,var
WriteLn>%script1%,wres,Let>HH=%var_1%*360
WriteLn>%script1%,wres,Let>MM=%var_2%*60
WriteLn>%script1%,wres,Let>startSS={(%var_3%+%HH%+%MM%)}
WriteLn>%script1%,wres,Separate>endtime,%SPACE%,mer
WriteLn>%script1%,wres,Separate>mer_1,:,var
WriteLn>%script1%,wres,Let>HH=%var_1%*360
WriteLn>%script1%,wres,Let>MM=%var_2%*60
WriteLn>%script1%,wres,Let>endSS={(%var_3%+%HH%+%MM%)}
WriteLn>%script1%,wres,Let>TotalSec=%endSS%-%startSS%
WriteLn>%script1%,wres,mdl>Complete in %percent%TotalSec%percent% seconds%percent%C%arel%F%percent%%starttime% to %endtime%%percent%C%arel%F%percent%%percent%C%arel%F%percent%%text%
WriteLn>%script1%,wres,Label>end

Label>BuildComplete
Macro>%script1%

Goto>start
Label>quit

SRT>ScrollingList
WriteLn>%script1%,wres, Let>newtext=%k%%percent%C%arel%F%percent%%text%
WriteLn>%script1%,wres, Let>text=%newtext%
END>ScrollingList

SRT>OneLineList
WriteLn>%script1%,wres, Let>text=%k%
END>OneLineList

SRT>Blank
WriteLn>%script1%,wres, Let>text=
END>Blank

SRT>SetTextMessage
WriteLn>%script1%,wres, SetControlText>Macro Scheduler Message*,TMemo,1,%text%
END>SetTextMessage

SRT>NormalMessage
WriteLn>%script1%,wres, Message>%text%
END>NormalMessage

SRT>DialogMessage
WriteLn>%script1%,wres,Dialog>Dialog4
WriteLn>%script1%,wres, Caption=Dialog Message
WriteLn>%script1%,wres, Width=238
WriteLn>%script1%,wres, Height=127
WriteLn>%script1%,wres, Top=200
WriteLn>%script1%,wres, Left=CENTER
WriteLn>%script1%,wres, Button=Ok,72,70,75,25,2
If>%dialog1.msradiogroup3.itemindex%=0
WriteLn>%script1%,wres, Label=%dialog1.msedit1% cycles %dialog1.msedit2% seconds per cycle,7,16
Else
WriteLn>%script1%,wres, Memo=msMemo1,17,5,200,50,%dialog1.msedit1% cycles %dialog1.msedit2% seconds per cycle
EndIf
WriteLn>%script1%,wres, Default=Ok
WriteLn>%script1%,wres,EndDialog>Dialog4
WriteLn>%script1%,wres,Show>dialog4
WriteLn>%script1%,wres,Label>start
WriteLn>%script1%,wres,GetDialogAction>dialog4,r4
WriteLn>%script1%,wres,If>r4=2,quit
WriteLn>%script1%,wres,Add>k,1
If>%dialog1.msradiogroup2.itemindex%=0,ScrollingList
If>%dialog1.msradiogroup2.itemindex%=1,OneLineList
If>%dialog1.msradiogroup2.itemindex%=2,Blank
If>%dialog1.msradiogroup3.itemindex%=0
WriteLn>%script1%,wres,Let>dialog4.msLabel1=%text%
Else
WriteLn>%script1%,wres,Let>dialog4.msMemo1=%text%
EndIF
WriteLn>%script1%,wres,ResetDialogAction>dialog4
WriteLn>%script1%,wres,Wait>%dwell%
WriteLn>%script1%,wres,If>%k%=%dialog1.msedit1%,done
WriteLn>%script1%,wres,Goto>start
WriteLn>%script1%,wres,Label>done
WriteLn>%script1%,wres,Gettime>endtime
WriteLn>%script1%,wres,CloseDialog>dialog4
WriteLn>%script1%,wres,Wait>0.1
WriteLn>%script1%,wres,Separate>starttime,%SPACE%,mer
WriteLn>%script1%,wres,Separate>mer_1,:,var
WriteLn>%script1%,wres,Let>HH=%var_1%*360
WriteLn>%script1%,wres,Let>MM=%var_2%*60
WriteLn>%script1%,wres,Let>startSS={(%var_3%+%HH%+%MM%)}
WriteLn>%script1%,wres,Separate>endtime,%SPACE%,mer
WriteLn>%script1%,wres,Separate>mer_1,:,var
WriteLn>%script1%,wres,Let>HH=%var_1%*360
WriteLn>%script1%,wres,Let>MM=%var_2%*60
WriteLn>%script1%,wres,Let>endSS={(%var_3%+%HH%+%MM%)}
WriteLn>%script1%,wres,Let>TotalSec=%endSS%-%startSS%
If>%dialog1.msradiogroup3.itemindex%=0
WriteLn>%script1%,wres,Let>dialog4.msLabel1=Complete in %percent%TotalSec%percent% seconds%percent%C%arel%F%percent%%starttime% to %endtime%%percent%C%arel%F%percent%%percent%C%arel%F%percent%%text%
Else
WriteLn>%script1%,wres,Let>dialog4.msMemo1=Complete in %percent%TotalSec%percent% seconds%percent%C%arel%F%percent%%starttime% to %endtime%%percent%C%arel%F%percent%%percent%C%arel%F%percent%%text%
EndIf
WriteLn>%script1%,wres,ResetDialogAction>dialog4
WriteLn>%script1%,wres,Show>dialog4,r4
WriteLn>%script1%,wres,Label>quit
Let>StopWrite=1
END>DialogMessage
Last edited by JRL on Tue Feb 06, 2007 11:13 pm, edited 1 time in total.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Feb 06, 2007 8:51 am

Dialog will be slower because you are using a label, but the message boxes use a memo field to display data. The memo field will handle much larger strings much better. You will notice the dialog test slowing up as the string gets longer. Try changing the label for a memo field and it will probably speed up.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Feb 06, 2007 11:17 pm

I've altered the script to give you a choice of displaying the text in a memo field or as a label when testing the write speed to a dialog.

I've tested up to 5000 lines and my results show the label display is faster but results may vary and perhaps 5000 lines isn't enough to stress the label.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Thu Feb 08, 2007 5:10 pm

Hi JRL,

In one of the tests, the dialog comes up a little small, you have to stretch it to see all of the memo field within... but nonetheless, thanks for a very instructive script. :)

I tried a few runs at 0.01 and 0.00 delay (showing the full list) and noticed some methods do slow down quite a bit as the string gets longer.

I am curious how tests of well over 5000 cycles would time out. Would one method emerge as the best? Would any or all of them slow down to the point of being unusable? Would any of them eventually crash? What are the upper limits if any?

An interesting exercise would be to add an "auto-mode" to your script so that it could run unattended to collect and save results. It could run through all the test combinations at 1000 reps and log the elapsed time (and test combo) to a line in a file, then double to 2000 reps and run them all again, double to 4000, and keep going until stopped by the user. Doubling may be too much at large numbers, perhaps just adding a 1000 reps each time would give more illustrative results.

Thanks again JRL for taking the time to write and post that script... very well done. Which method shall emerge as the best at huge reps? Perhaps time will tell.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Feb 08, 2007 5:59 pm

In one of the tests, the dialog comes up a little small, you have to stretch it to see all of the memo field within.
It works fine for me but if it is too small for you simply change the size of the dialog. For example: the lines

WriteLn>%script1%,wres, Width=238
WriteLn>%script1%,wres, Height=127

might become:
WriteLn>%script1%,wres, Width=238
WriteLn>%script1%,wres, Height=250


You probably want to move the button also:
WriteLn>%script1%,wres, Button=Ok,72,70,75,25,2
could be:
WriteLn>%script1%,wres, Button=Ok,72,200,75,25,2

As for "auto-mode", I thought about doing something like that and writing the results to a spreadsheet. However, after running this a few times and getting different results for the same settings I'm thinking that it provides enough info to generalize and in general I think that the fastest method overall is to use a dialog box and a label. In general... wouldn't you agree?

Later,
Dick

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts