Author |
Topic: LBB runs 7 times slower than LB on my GBRL-Sender (Read 1552 times) |
|
xtal
New Member
member is offline
Gender:
Posts: 27
|
|
LBB runs 7 times slower than LB on my GBRL-Sender
« Thread started on: Oct 24th, 2017, 2:08pm » |
|
I have a LB-pro 4.5.1 GRBL-Sender in progress, I tried compiling /running with LBB ,,, 1st problem > required changing Comport opening ... '''open P$;":";BaudRate$;",n,8,1,ds0,cs0,rs" for random as #GRBL ' LB open P$;":";BaudRate$;",n,8,1" for random as #GRBL ' LBB
I have a loop timer running for status interrogating after opening the comm port,,,, LB 4.5.1 pro time loop is 33 seconds LBB 3.09 time loop is 229 seconds
an LB compiled + files zip file is available @
https://sabercathost.com/52ft/LBsave1.zip
I would prefer to use a single exe file instead of exe and many dll's
I also have zip file 676KB but apparently no way to attach
another link: http://www.filehosting.org/file/details/701092/LBB-save.zip
note: using W10
|
« Last Edit: Oct 24th, 2017, 5:39pm by xtal » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #1 on: Oct 24th, 2017, 9:13pm » |
|
on Oct 24th, 2017, 2:08pm, xtal wrote:I would prefer to use a single exe file instead of exe and many dll's |
|
If LBB is running significantly more slowly than LB 4 it would suggest that your program is 'untypical'. For example it may be making heavy use of one of the features of Liberty BASIC that is not natively supported by BBC BASIC and therefore needs to be emulated - slowly - at run-time. Here are some examples of things which are slow in LBB and should be avoided for best performance:
The WORD$() function (it's rarely the best way of doing things anyway).
Calling SCAN far more often than you need to.
Repeatedly opening-and-closing windows. It's faster to leave them open but hide/show them when required.
Sending many, separate, graphics commands; instead concatenate them into a long string containing multiple commands.
GOSUB, which is deprecated; generally CALL is faster. GOTO is slow too, but you wouldn't use that, would you?! You can easily discover where the time is being spent by using the 'Profile' capability of LBB (Run... Profile Program or Ctrl+F5). This should make it obvious where in the program you may need to make adjustments to 'tune' it for best performance in LBB.
Richard.
|
|
|
|
xtal
New Member
member is offline
Gender:
Posts: 27
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #2 on: Oct 25th, 2017, 3:36pm » |
|
It would have to be GOSUB, which is deprecated; generally CALL is faster. GOTO is slow too, but you wouldn't use that, would you?! grin .. I would like to see any code that does a lot, that doesn't contain branch instructions ie goto's as for call vs gosub , put return on stack - then branch -then return ...why would there be a difference?
Tried the profile all that it showed was what I would expect , updating display..
The program's timing is slaved to [LoopExit] timmer 3 [ckbuf] - wait [ckbuf] inc ctr to 1775 - display time - set ctr to 0 if ctr and 31 =31 send status request to GRBL else goto [LoopExit] end if
get/save Comm data - in this case GRBL status chk if CrLf rcvd - process -update/display text boxes etc repeat ---
HM....I forgot how the code works , I think I see where I can improve .... Thx
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #3 on: Oct 25th, 2017, 10:35pm » |
|
on Oct 25th, 2017, 3:36pm, xtal wrote:I would like to see any code that does a lot, that doesn't contain branch instructions ie goto's |
|
Oh, come on! GOTO was deprecated decades ago (remember Edsger Dijkstra's letter "Go To Statement Considered Harmful" back in 1968). Of course it's true that some early BASICs provided no alternative, forcing programmers to use GOTO - with an explosion of 'spaghetti code' as a result.
But since sometime in the 1980s most BASICs have provided structured alternatives (BBC BASIC was one of the first to do so, in 1981) and now there is little excuse for using GOTO - I would say none but there are those who insist it still has its uses for things like error handling (but LBB has SEH for that).
Indeed I would turn your statement on its head: show me any "code that does a lot" which is improved by using GOTO rather than Structured Programming constructs (WHILE, DO etc.). It never occurs to me to use GOTO because I have been writing structured BASIC code for at least the last 35 years!
And by the way, LB Booster itself is written in BASIC: over 200 kilobytes of code with not a single GOTO or GOSUB anywhere!
Richard.
|
|
|
|
xtal
New Member
member is offline
Gender:
Posts: 27
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #4 on: Oct 25th, 2017, 11:48pm » |
|
I was mainly into computer HW for 50 yr and as a side line, I dabbled in programming. 1964-65 Iowa State University Engineering built computer 4k vacuum tube memory Language = Genie [bet you never heard of that]... 65-66 GE Computers was introduced to their assembly 66-68 US army RCA 501 & RCA 301 used machine lang and assembly 68-72 RCA Spectra Series HW and SW engineer mainly Assembly Lang 72-2013 Univac - Sperry Rand - Sperry - Unisys mainly hardware e
I grew up with machine code, around 1984 RCA introduced the Cosmac Elf 8082 I could only afford to buy the 8082 Built Computer that had 4k ram, tape casette, TV, and Keyboard from keypunch.. I programmed OS for ELF OS for COSMAC ELF 8082 with 4K ram Capable of handling 16 program slots and handling many IO slots [but due to memory restraints could only run 3 slots] This was all done in machine code!
Played more with assembly, then some RPG, then more basic[micro-controller], and C++[Arduino].
I've just been seriously playing with LB for the last 6 months writing a GCode sender program to interface with GRBL. I've used some structured code, which is usually ends up BLOATED and wasting memory, but these days memory is cheap, so why worry about it!
I guess I'm like my grandparents, they just could not waste water[they went thru the big water drought], I just don't want to waste memory [many years I had memory drought].
So I'll keep using goto's, and I like spaghetti, and its easy to control if you are willing to put forth the effort . I find it easier to debug than so called structured, but then my code is structured my way
Lets face it While-Wend & Do-Loop in machine code are no more than: [TAG Location] do-something - GOTO [TAG Location]
Structured just hides the goto's
|
|
Logged
|
|
|
|
michael
New Member
member is offline
Posts: 28
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #5 on: Oct 26th, 2017, 03:27am » |
|
If your talking assembly language
There is no GOTO but there is:
JMP -- Jump unconditionally to label and many more conditional statements that you can mix within a basic program.
If you like assembly language perhaps you will like BBC Basic For Windows, since it has the best of all worlds.
http://www.rtrussell.co.uk/index.html
I only suggest this since there is such a emphasis on that subject. And well, BBC Basic would be A LOT easier to manage than assembly language by itself.
OH and if you really want to.. GOTO and GOSUB are within BBC Basic too.
[labels] are ok, but DEF PROC and DEF FN are far more convienient.
Richard is correct about GOTO. Its more coding, slower, and really has no purpose other than for perhaps a tiny snippet for testing something...
I used to use GOTO and GOSUB all the time.. I only speak of the subject just for this..
|
« Last Edit: Oct 26th, 2017, 03:35am by michael » |
Logged
|
I make program generators and some utilities. Its my hobby
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #6 on: Oct 26th, 2017, 08:52am » |
|
on Oct 26th, 2017, 03:27am, michael wrote:If you like assembly language perhaps you will like BBC Basic For Windows, since it has the best of all worlds. |
|
Liberty BASIC is better (at least, LBB is)! I would never recommend that anybody move from LB to BBC BASIC. I use Liberty BASIC myself, in preference, whenever I want to write a program containing GUI elements and/or sprites; both have far better support in LB (so long as it's for running on Windows of course).
It's LBB that is "the best of all worlds", not BBC BASIC. Pretty much anything you can do in BBC BASIC you can do in LBB (even assembler code, if you are careful) simply because you can incorporate BBC statements in a LBB program (by prefixing the statements with an exclamation mark) but the reverse isn't true.
Admittedly if I want to run a program in Mac OS or Linux or Android, or on a Raspberry Pi, then I do use BBC BASIC because there is a cross-platform version. Despite various announcements over the years, there will probably never be a cross-platform implementation of Liberty BASIC.
Of course, under limited circumstances (e.g. when there are no GUI or graphics elements), you can use LBB as a 'Liberty BASIC to BBC BASIC translator' and by that means run a program originally written in LB on those other platforms. Select 'Show LBB pane' in the Options menu to see the translation.
Richard.
|
|
Logged
|
|
|
|
xtal
New Member
member is offline
Gender:
Posts: 27
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #7 on: Dec 21st, 2017, 9:06pm » |
|
The problem seems to be associated with timer xx,[jump] I have stripped down coding , but is too big to post, I will try to remove buttons/etc...
I have noticed a quirk I can't explain, I enabled print window and added print Qcnt.... This runs slow until I move the print window, then it speeds up ??? LBBrun runs slower than LB 46 sec vs 28 sec LBB exec runs 450 sec ---- below is code without page format -change print to #main.WinStatus, Qcnt
Code:
bucketdelay=3
'------------------------------------------------------------------------------------------------------
Thirty=time$("seconds") ' seconds since midnight '
Open "Liberty Basic GRBL GUI" for Window as #main '
#main "trapclose [quit]" '
'----------------------------------------------------------------------------------------------------
#main.GCwindow, "TotalScreen Width = "; DisplayWidth '
#main.GCwindow, "TotalScreen Height = "; DisplayHeight '
x$=time$() ' setup 1st time msg
TmvalNu=val(mid$(x$,4,2))*60 ' setup 1st time msg
TsvalNu=val(right$(x$,2))+TmvalNu ' setup 1st time msg
'=======================================================================================================
[LoadMacros] '' code removed '
[Glog] '' code removed '
[ErrLoop1] '' code removed '
[LoopExit] '' code removed ' wait for user input
timer bucketdelay, [ckbuf] ' every 3 ms ckbuf
wait '
'--------------------------------------------------------------------------------------------------------
[ckbuf] '
Qcnt=Qcnt+1 '
'' print Qcnt;"-"; '' added speeds up when move window
#main.WinStatus, Qcnt '' trying this
'--------------------------------------------------------------------------------------------------------
if Qcnt >1775 then ' approx 30+ sec elapsed
x$=time$() '
TsvalOld=TsvalNu ' last total seconds -> old
TmvalOld=TmvalNu ' last m*60 seconds -> old
TmvalNu=val(mid$(x$,4,2))*60 ' get nu m *60 seconds 9*60=540 0*60=0 ==600
TsvalNu=val(right$(x$,2))+TmvalNu ' compute new total seconds
xx = abs(TsvalNu-TsvalOld) ' compute new-old
#main.GCwindow, "<";Qcnt;"> <";xx;"> ";x$ ' 1st display & every hour = funny number
Qcnt=0 '
end if '
if CommOpen=0 then [LoopExit] ' can't get input if comm closed
'-----------------------------------------------------------------------------------------------------
[getbuffer] '' code removed '
'-----------------------------------------------------------------------------------------------------
[getmessage] '' code removed '
[loopx] '' code removed '
'------------------------------------------------------------------------------------------------------
[PreProcess] '
'' timer 0 ' stop timer until line processed *****
'' code removed
[StepWait]
'' code removed
'==================================================================================================
[PrintResponse] ' 3 ms 28a
'' code removed
goto [LoopExit] ' **************************
'==================================================================================================
[ESTOP]
'==================================================================================================
[quit] '
'' code removed
close #main ' main window
END ' must stop main
|
« Last Edit: Dec 21st, 2017, 9:10pm by xtal » |
Logged
|
|
|
|
xtal
New Member
member is offline
Gender:
Posts: 27
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #8 on: Dec 21st, 2017, 9:41pm » |
|
After removing 90% of my button, etc. LBBrun is 28 sec LBB exe is 100 seconds LB is 28 seconds
hmmmm LBB has problem with how many buttons etc???? I have approx 130 buttons 12 graphic boxes 2 text editor 7 list boxes 6 text boxes 4 combo boxes 15 statictext Code:
[InitColors]
'Please use default colors when possible.
'ForegroundColor$ = "Black"
'BackgroundColor$ = "Buttonface"
True = 1 : False = 0
'------------
[WindowSetup]
NOMAINWIN ' allow no print window
WindowWidth = 1020 : WindowHeight = 700 '877
UpperLeftX = INT((DisplayWidth-WindowWidth)/2) ' UpperLeftX = DisplayWidth-WindowWidth
UpperLeftY = INT((DisplayHeight-WindowHeight)/2) ' UpperLeftY = DisplayHeight-WindowHeight
Menu #main, "DROreset", "Reset MPX", [ZX], "Reset MPY", [MZY], "Reset MPZ", [MZZ], "ResetALL", [MZR]
Menu #main, "HELP", "Q/A.txt", [HELPx],"LibertyBasic.chm",[HELPchm],"LB-Forum",[HELPforum]
bucketdelay=3
'--------------
[ControlSetup]
'--------------
statictext #main.statictext2, "MPOS", 60, 105, 40, 20
statictext #main.statictext3, "WCO", 230, 105, 25, 20
statictext #main.statictext4, "WPOS", 350, 105, 40, 20
textbox #main.ManualTx, 5, 475, 470, 20 ' over-down-width-height
stylebits #main.Enter, _BS_DEFPUSHBUTTON,0,0,0 ' Enable ENTER Key
button #main.Enter,"",[Enter],UL,473,475,5,20 ' hidden button sort of !
button #main.ManualSend, "SEND COMMANDS", [SEND], UL, 190, 500, 180, 20
'===========
texteditor #main.WinStatus, 55,125, 420, 80 ' LBB adjust ' Top left Corner - over, down
texteditor #main.GCwindow, 55, 210, 420, 260 ' LBB adjust ' bottom right - width, down
stylebits #main.Mag1, _ES_CENTER,0,0,0 '
textbox #main.Mag1, 435, 575, 40, 20 '
button #main.rtz, "RTNZERO", [Ret2ZERO], UL, 375, 600, 60, 30 '
button #main.magnify, "MAG",[MAGNIFY],UL,435,600,40,30 '**************
stylebits #main.PLOTa, _ES_CENTER,0,0,0 '
textbox #main.PLOTa, 435, 525, 40, 20 '
button #main.plotting, "PLOT",[PLOTXY],UL,435,550,40,20 ' '
graphicbox #main.Status, 188, 522, 180, 50 ' **************
'---------
button #main.MZX, "Zx", [MZX], UL, 165, 0, 30, 30 '
button #main.MZY, "Zy", [MZY], UL, 165, 35, 30, 30 '
button #main.MZZ, "Zz", [MZZ], UL, 165, 70, 30, 30 '
button #main.MZR, "ZR", [MZR], UL, 195, 0, 25, 100 '
stylebits #main.DROMPx, _ES_RIGHT,0,0,0 '
textbox #main.DROMPx, 55, 0, 110, 30 ' Right Justify & TextboxColor$ = "White"
stylebits #main.DROMPy, _ES_RIGHT,0,0,0 '
textbox #main.DROMPy, 55, 35, 110, 30 '
stylebits #main.DROMPz, _ES_RIGHT,0,0,0 '
textbox #main.DROMPz, 55, 70, 110, 30 '
stylebits #main.DROWCx, _ES_RIGHT,0,0,0 '
textbox #main.DROWCx, 220, 0, 110, 30 '
stylebits #main.DROWCy, _ES_RIGHT,0,0,0 '
textbox #main.DROWCy, 220, 35, 110, 30 '
stylebits #main.DROWCz, _ES_RIGHT,0,0,0 '
textbox #main.DROWCz, 220, 70, 110, 30 '
stylebits #main.DROWPx, _ES_RIGHT,0,0,0 '
textbox #main.DROWPx, 330, 0, 110, 30 '480 '
stylebits #main.DROWPy, _ES_RIGHT,0,0,0 '
textbox #main.DROWPy, 330, 35, 110, 30 '
stylebits #main.DROWPz, _ES_RIGHT,0,0,0 '
textbox #main.DROWPz, 330, 70, 110, 30 '
'------------
listbox #main.S1, SA$(),[Prm1],476,125,102,108 '
listbox #main.S2, SB$(),[Prm2],580,125,102,108 '
listbox #main.S3, SC$(),[Prm3],686,125,102,108 '
listbox #main.S4, SD$(),[Prm4],792,125,102,108 '
listbox #main.S5, SE$(),[Prm5],898,125,102,108 '
texteditor #main.PopUp, 500, 250, 475,350 '
graphicbox #main.Plot3, 476, 235, 525,405 ' home is 0,405
' START UP VALUES
Thirty=time$("seconds") ' seconds since midnight '
Open "Liberty Basic GRBL GUI" for Window as #main '
#main "trapclose [quit]" '
'------------
#main.GCwindow, "TotalScreen Width = "; DisplayWidth '
#main.GCwindow, "TotalScreen Height = "; DisplayHeight '
x$=time$() ' setup 1st time msg
TmvalNu=val(mid$(x$,4,2))*60 ' setup 1st time msg
TsvalNu=val(right$(x$,2))+TmvalNu ' setup 1st time msg
'=============
[LoadMacros] '' code removed '
[Glog] '' code removed '
[ErrLoop1] '' code removed '
[LoopExit] '' code removed ' wait for user input
timer bucketdelay, [ckbuf] ' every 3 ms ckbuf
wait '
'--------------------------------------------------------------------------------------------------------
[ckbuf] '
Qcnt=Qcnt+1 '
'' print Qcnt;"-"; '' added speeds up when move window
#main.WinStatus, Qcnt '' trying this
'--------------------------------------------------------------------------------------------------------
if Qcnt >1775 then ' approx 30+ sec elapsed
x$=time$() '
TsvalOld=TsvalNu ' last total seconds -> old
TmvalOld=TmvalNu ' last m*60 seconds -> old
TmvalNu=val(mid$(x$,4,2))*60 ' get nu m *60 seconds 9*60=540 0*60=0 ==600
TsvalNu=val(right$(x$,2))+TmvalNu ' compute new total seconds
xx = abs(TsvalNu-TsvalOld) ' compute new-old
#main.GCwindow, "<";Qcnt;"> <";xx;"> ";x$ ' 1st display & every hour = funny number
Qcnt=0 '
end if '
if CommOpen=0 then [LoopExit] ' can't get input if comm closed
'------------[getbuffer] '' code removed '
[getmessage] '' code removed '
[loopx] '' code removed '
[PreProcess] '
'' timer 0 ' stop timer until line processed *****
'' code removed
[StepWait]
'' code removed
[PrintResponse] ' 3 ms 28a
'' code removed
goto [LoopExit] ' **************************
[ESTOP]
[quit] '
'' code removed
close #main ' main window
END ' must stop main
|
« Last Edit: Dec 21st, 2017, 9:49pm by xtal » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #9 on: Dec 21st, 2017, 10:44pm » |
|
on Dec 21st, 2017, 9:41pm, xtal wrote:This runs slow until I move the print window, then it speeds up ? |
|
This is almost certainly a sign of CPU throttling. If you are using a laptop it is not uncommon. Go into Windows' performance settings and force the CPU to run at full speed: it will drain the battery, but at least anomalies such as this shouldn't happen.
Quote:After removing 90% of my button, etc. LBBrun is 28 sec LBB exe is 100 seconds LB is 28 seconds |
|
There are three ways of running a program using LBB: one is to run it from the LBB IDE, the second is to 'compile' it to an EXE and run that, the third way is to export a tokenised program and run that using LBBRUN.exe.
Because of the way LBB works, there will never be a significant difference between the execution speed of these three methods. The 'compiled' EXE may be slightly faster than the other two, but only a few percent at most.
I think I said this before, but if you want to find out why LBB is slower than LB, then use the profiler (Run... Profile Program menu selection or Ctrl+F5). This will show you exactly where the time is being spent.
I could make LBB significantly faster than it is, by replacing the LBLIB library (coded in BBC BASIC - one of the slowest BASICs) with a DLL coded in C. But I'm not going to do that, partly because it would be a lot of work and partly because LBB is intended to be a showcase for BBC BASIC.
Richard.
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #10 on: Dec 22nd, 2017, 12:11am » |
|
on Dec 21st, 2017, 9:41pm, xtal wrote: Code:
bucketdelay=3
timer bucketdelay, [ckbuf] ' every 3 ms ckbuf
wait |
|
Don't forget that, in both LB 4 and LBB, the shortest timer period is about 10 ms. Attempting to set it to 3 ms, as in your code, won't result in an error but it won't make it any faster.
Richard.
|
|
Logged
|
|
|
|
xtal
New Member
member is offline
Gender:
Posts: 27
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #11 on: Dec 22nd, 2017, 11:11am » |
|
Thx for the 3 ms info, I knew there was a limit somewhere , just didn't know what it was
As for CPU Throttle ? I'm running a QuadCore Desktop with 8GB memory, So I don't suspect any throttling and will attempt to check it out, but if that is the problem then why moving the print window would make it speed up
And why the speed increase after removing many button's etc,, the screen display only has 2 texteditor windows in play in this example
|
« Last Edit: Dec 22nd, 2017, 11:18am by xtal » |
Logged
|
|
|
|
tsh73
Full Member
member is offline
Gender:
Posts: 210
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #12 on: Dec 22nd, 2017, 12:58pm » |
|
xtal, I've run your code from Reply #8 (EDIT: on Win XP upon Intel Core I5) LBB 28 sec produced EXE 28 sec produced LBB, run with LBBRUN.exe 28 sec
BTW 1776*0.016 is 28.416
So if you have more that should mean some stuff between WAIT took more then 16 ms (not say 3 ms your planned) (so it fired on next 16'th. Or some next after that)
You probably should try profiler to see that takes time.
|
« Last Edit: Dec 22nd, 2017, 12:59pm by tsh73 » |
Logged
|
|
|
|
Rod
Full Member
member is offline
Gender:
Posts: 110
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #13 on: Dec 22nd, 2017, 1:32pm » |
|
Anything to do with the Windows timer takes time. Free running your code was looping in 0-1 second on my machine. introducing any form of time$( timer function drags the system down. As Richard says it adds 10 or more milliseconds of wasted time per loop. If you need it to run that fast consider other code as a time waster, or worst case a while wend loop that balances the time delay you need.
But why are you needing the delay? if the display is live and reading stuff real time what is the point of the delay?
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: LBB runs 7 times slower than LB on my GBRL-Sen
« Reply #14 on: Dec 22nd, 2017, 4:14pm » |
|
on Dec 22nd, 2017, 11:11am, xtal wrote:but if that is the problem then why moving the print window would make it speed up |
|
Windows gives processes that the user is interacting with a higher priority, so it's possible that moving a window may increase the CPU clock rate of the core that your program is running on. You can try using a tool like CPU-Z to monitor the clock speeds.
Quote:And why the speed increase after removing many button's etc |
|
Most likely a coincidence. One plausible way in which the presence of many buttons could affect execution speed is if the additional memory usage causes cache thrashing. But I would expect the effect to be small.
In your program most of the time (around 90% here) is spent in the WAIT statement, as you would expect, so the execution time is pretty much determined by that.
Don't speculate, run the profiler!
Richard.
|
|
Logged
|
|
|
|
|