viewpoint-particle

Author Topic: background processing slow with boxopen  (Read 3032 times)

alpaykasal

  • Newbie
  • *
  • Posts: 4
background processing slow with boxopen
« on: December 22, 2013, 04:17:25 am »
Greetings, I am parsing large gcode files (plain text) and it all works, but because it can take a minute or two to complete processing, i am using boxopen and boxtext to display a "please wait" message during background processing.

with boxopen, my parsing slows way down, by a large factor. without any visual feedback of the boxopen command, my parsing is done in a minute. i don't really need my boxopen to update with dynamic text (I assume things are slowed down because the box is able to be dynamically linked to the concurrent parsing).

any solutions? would this slow-down disappear if the wbt is compiled? i'm running through the interpreter at the moment.

Thanks in advance.

alpaykasal

  • Newbie
  • *
  • Posts: 4
Re: background processing slow with boxopen
« Reply #1 on: December 22, 2013, 04:24:31 am »
btw, my workaround was to split the boxopen portion into a separate wbt file and use the clipboard as communication. here is the code. previously, this was basically in my main wbt. i prefer this all live in one exe ultimately, so i'd love help in figuring out the slow-down. thanks again.



Code: [Select]
;filameter progress

versionstring="v1"
:looper
tempo=clipget()
if tempo==1 then BoxOpen("Filameter %versionstring%",0)
while tempo==1
   BoxText("Gcode being processed. Please wait. This could take several minutes.")
   tempo=clipget()
endwhile
boxshut()
tempo=clipget()
if tempo!="terminate" then goto looper

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: background processing slow with boxopen
« Reply #2 on: December 23, 2013, 08:19:52 am »
Difficult to say what might be causing the slow down with out seeing the original code. Please post the original code ( where all the code was contained in a single script ).

Deana F.
Technical Support
Wilson WindowWare Inc.

alpaykasal

  • Newbie
  • *
  • Posts: 4
Re: background processing slow with boxopen
« Reply #3 on: December 23, 2013, 10:43:24 pm »
thanks for your time.

I figured something out... with Boxtext inside my WHILE operations, it took 5min 5secs to process. When I moved the Boxtext line outside of the WHILE loop (I placed it just before WHILE), processing time was reduced to 13 seconds. Huge difference. I am fine keeping boxtext outside of the loop,but i'd appreciate your input on this anyway. Thanks again.

Code: [Select]
;Filameter by Alpay Kasal of the Supertouch Group

clipput("0")
filename=AskFilename("SelectFile", "C:\Users\alpay\My Things", "*.gcode|*.gcode|*.txt|*.txt", "R2FrontPanel.gcode", 1)
handle=FileOpen(filename, "READ")
count = 0
versionstring="v1"
gcodesource=""
Evalue=""
Avalue=""
pos=""
checker=""
checkskein=0

BoxOpen("Filameter %versionstring%",0)
;BoxText("Gcode being processed. Please wait. Processing line %count%")
While @TRUE ; Loop till break do us end
   BoxText("Gcode being processed. Please wait. Processing line %count%")
   line = FileRead(handle)
   checkskein1=strindex(line,"skeinforge gcode",0,@FWDSCAN)
   checkskein=checkskein+checkskein1
   posb=strindex(line,"G1 E",0,@FWDSCAN)
   if posb!=0
posdot=strindex(line,".",posb,@FWDSCAN)
Evalue=strsub(line,posb+4,posdot-posb-4)
Einch=strfix(Evalue/25.4," ",5)
   endif
   if strindex(line,"; End of print",0,@FWDSCAN)!=0
posa=strindex(line,"A",strindex(line,"; End of print",0,@FWDSCAN),@BACKSCAN)
possemicolon=strindex(line,".",posa,@FWDSCAN)
Avalue=strsub(line,posa+1,possemicolon-posa-1)
Ainch=strfix(Avalue/25.4," ",5)
   endif
   If line == "*EOF*" Then Break
   count = count + 1
EndWhile
FileClose(handle)
boxshut()
message("Filameter %versionstring%","Processed %count% lines of Gcode.")
if checkskein!=0
message("Filameter %versionstring%","Skeinforge results : %Evalue% mm, or %Einch% inches")
else
message("Filameter %versionstring%","Makerware results : %Avalue% mm, or %Ainch% inches")
endif

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: background processing slow with boxopen
« Reply #4 on: December 24, 2013, 09:17:27 am »
BoxText will definitely add overhead to the script. The script needs to update the GUI which can delay the other operations. So it becomes a decision of the developer as to whaty is more important. Speed or visual information. I recommend using the BoxesUp & BoxDrawText functions if you need speedy GUI updates.

Here is a code sample comparing the routines.

Code: Winbatch
Decimals(3)
count = 1
maxlimit = 250

;TEST - BOXTEXT INSIDE
begintime=GetTickCount()
BoxOpen("Filameter %versionstring%",0)
While @TRUE ; Loop till break do us end
   BoxText("Gcode being processed. Please wait. Processing line %count%")
   if count > maxlimit then break
   count = count + 1
EndWhile
BoxShut()
endtime=GetTickCount()
timeinseconds=(endtime-begintime)/1000.0
Pause("Boxtext INSIDE loop Results",timeinseconds)


;RESET
count = 1


;TEST - BOXTEXT OUTSIDE
begintime=GetTickCount()
BoxOpen("Filameter %versionstring%",0)
BoxText("Gcode being processed. Please wait.")
While @TRUE ; Loop till break do us end
   if count > maxlimit then break
   count = count + 1
EndWhile
BoxShut()
endtime=GetTickCount()
timeinseconds=(endtime-begintime)/1000.0
Pause("Boxtext OUTSIDE loop Results",timeinseconds)


;RESET
count = 1


;TEST - BoxesUp & BoxDrawText
begintime=GetTickCount()
BoxesUp("200,200,800,800", @NORMAL)
BoxCaption(1, "Filameter %versionstring%")
BoxDataTag(1,"ACORN")
While @TRUE ; Loop till break do us end
   BoxDataClear(1,"ACORN")
   BoxDrawText(1, "200,200,750,250", "Gcode being processed. Please wait. Processing line %count%", @TRUE, 1)
   if count > maxlimit then break
   count = count + 1
EndWhile
BoxDestroy(1)
endtime=GetTickCount()
timeinseconds=(endtime-begintime)/1000.0
Pause("BoxesUp & BoxDrawText Results",timeinseconds)
exit






Deana F.
Technical Support
Wilson WindowWare Inc.

alpaykasal

  • Newbie
  • *
  • Posts: 4
Re: background processing slow with boxopen
« Reply #5 on: December 26, 2013, 01:47:14 am »
Thank you so much, very helpful reply... I opted for a middle ground, I am updating the gui from inside the loop, but i am updating it much less often.

i'd like to say that splitting the the code into a separate wbt to only handle gui, and using the clipboard (clipput and clipget) as a way to communicate, DEFINITELY was the most responsive route, which tells me that threading is key. I've been using winbatch for years, for many many simple tasks, and used master scripts to spawn child scripts, my poor mans multithreading... but right now, i wish I could do it all from within one .exe

here is the latest version of my little utility for searchable posterity:

Code: [Select]

;Filameter by Alpay Kasal of the Supertouch Group http://www.Supertou.ch

;function to round to significant number found at techsupt.winbatch.com
#DefineFunction sigr(value,sigfigs)    ; round to desired number of significant digits
   e=sigfigs-(1+Int(Log10(Abs(value)))); compute power of 10 needed
   multdiv= 10.0**e                    ; create the E notation number
   ret= Int(value*multdiv)/multdiv     ; adjust, simple round, unadjust
   Return(Int(ret))                    ; ta-da
#EndFunction

;unecessary cleanup i used during testing large loops
clipput("0")
count=0
county=0
countz=0
versionstring="v1"
gcodesource=""
Evalue=""
Avalue=""
pos=""
checker=""
checkskein=0


filename=AskFilename("SelectFile", "C:\Users\alpay\My Things", "*.gcode|*.gcode|*.txt|*.txt", "R2FrontPanel.gcode", 1)
handle=FileOpen(filename, "READ")
begintime=GetTickCount()
BoxesUp("200,200,800,600", @NORMAL)
BoxCaption(1, "Filameter %versionstring%")
BoxDataTag(1,"ACORN")
While @TRUE
   BoxDataClear(1,"ACORN")
   if count>100 then countz=sigr(count,3)
   if countz!=county ;check equality to ONLY do a BoxDrawText on a var change since iterations of gui update incur a performance hit
county=countz
BoxDrawText(1, "200,200,750,50", "Gcode being processed. Please wait. Processing line %county%", @TRUE, 1)
   endif
   line = FileRead(handle)
   checkskein1=strindex(line,"skeinforge gcode",0,@FWDSCAN)
   checkskein=checkskein+checkskein1
   posb=strindex(line,"G1 E",0,@FWDSCAN)
   if posb!=0
posdot=strindex(line,".",posb,@FWDSCAN)
Evalue=strsub(line,posb+4,posdot-posb-4)
Einch=strfix(Evalue/25.4," ",5)
   endif
   if strindex(line,"; End of print",0,@FWDSCAN)!=0
posa=strindex(line,"A",strindex(line,"; End of print",0,@FWDSCAN),@BACKSCAN)
possemicolon=strindex(line,".",posa,@FWDSCAN)
Avalue=strsub(line,posa+1,possemicolon-posa-1)
Ainch=strfix(Avalue/25.4," ",5)
   endif
   If line == "*EOF*" Then Break
   count = count + 1
EndWhile
FileClose(handle)
BoxDestroy(1)
endtime=GetTickCount()
timeinseconds=abs((endtime-begintime)/1000.0)

message("Filameter %versionstring%","Processed %count% lines of Gcode in %timeinseconds% seconds.")
if checkskein!=0
message("Filameter %versionstring%","Skeinforge results : %Evalue% mm, or %Einch% inches")
else
message("Filameter %versionstring%","Makerware results : %Avalue% mm, or %Ainch% inches")
endif
exit