Timer in SuperBasic?
Timer in SuperBasic?
I was searching for a usable timer in Superbasic...
Like Millis for Arduino for instances
Does Anyone know?
Like Millis for Arduino for instances
Does Anyone know?
-
- Aurora
- Posts: 890
- Joined: Mon Nov 24, 2014 2:03 pm
Re: Timer in SuperBasic?
Hi NL_QL_USR,
Here is a 1 ko basic code-timer. ( General programming advice : You only need to optimise the innermost loops of your code !).
For consistancy, exclude as many running jobs as you can, except for Basic itself, else suffer from very unreliable results !
But as the routine uses the system clock, results are very reliable.
UNZIP Code_Timer_bas and RUN it once. (Tweak Line 170 with the final printed result). Then UnREMark line 265 and run again.
Now this is a comparitive number taken by the example ( a FOR loop : timing 256 screen clearances with different paper colours.)
Between lines 241 and 279 you can include 38 lines of your own inner loop code to compare, as you optimise your code, (or renum).
Results will of course change on each system setup, depending on proceesor speed and overheads. Valuable for any one system though.
I wrote this program to compare the relative efficiencies of all Superbasic keywords back in the '80s. Very surprising results at the time !
Here is a 1 ko basic code-timer. ( General programming advice : You only need to optimise the innermost loops of your code !).
For consistancy, exclude as many running jobs as you can, except for Basic itself, else suffer from very unreliable results !
But as the routine uses the system clock, results are very reliable.
UNZIP Code_Timer_bas and RUN it once. (Tweak Line 170 with the final printed result). Then UnREMark line 265 and run again.
Now this is a comparitive number taken by the example ( a FOR loop : timing 256 screen clearances with different paper colours.)
Between lines 241 and 279 you can include 38 lines of your own inner loop code to compare, as you optimise your code, (or renum).
Results will of course change on each system setup, depending on proceesor speed and overheads. Valuable for any one system though.
I wrote this program to compare the relative efficiencies of all Superbasic keywords back in the '80s. Very surprising results at the time !
Re: Timer in SuperBasic?
Thanks Stevestevepoole wrote: Sun Jul 21, 2024 12:17 am Hi NL_QL_USR,
Here is a 1 ko basic code-timer. ( General programming advice : You only need to optimise the innermost loops of your code !).
For consistancy, exclude as many running jobs as you can, except for Basic itself, else suffer from very unreliable results !
But as the routine uses the system clock, results are very reliable.
Works fast and nice...
A ideal Timer should be on all systems the same click off course
But your example is good to be used in many programs
I also tried your Cave.bas .... Nice!!!
Re: Timer in SuperBasic?
Hi Steve,
Code_Timer
I think some Tool Kits might use COUNT as a KEYWORD so suggest Counts instead. Just a thought I might be wrong; Line 190 REPeat r requires an END REPeat r such as at Line 322 otherwise will be stuck on 190 until IF statement fulfilled thereby 200 to 320 being executed at end of each count not within each timer count.
QBITS
Code_Timer
I think some Tool Kits might use COUNT as a KEYWORD so suggest Counts instead. Just a thought I might be wrong; Line 190 REPeat r requires an END REPeat r such as at Line 322 otherwise will be stuck on 190 until IF statement fulfilled thereby 200 to 320 being executed at end of each count not within each timer count.
QBITS
-
- Aurora
- Posts: 890
- Joined: Mon Nov 24, 2014 2:03 pm
Re: Timer in SuperBasic?
Hi Qbits,
Yes, COUNT would be better if written as counts as you suggest, for compatibility.
As for line 190, the code is correct, as line 280 needs to be aligned on the clock tick, which is only accurate every second...
Perhaps the code would run faster if intergerised, (but that would not work under QDOS).
Best wishes, and good health, Steve.
____________________________________
Yes, COUNT would be better if written as counts as you suggest, for compatibility.
As for line 190, the code is correct, as line 280 needs to be aligned on the clock tick, which is only accurate every second...
Perhaps the code would run faster if intergerised, (but that would not work under QDOS).
Best wishes, and good health, Steve.
____________________________________
Re: Timer in SuperBasic?
https://dilwyn.theqlforum.com/docs/basic/index.html
On that page you can find some lists of keyword names used in S*BASIC and various toolkits, so that you can choose variable, proc and fn names which don't clash with existing keyword names.
The SuperBASIC Reference Manual online is also very useful for this:
https://superbasic-manual.readthedocs.io/en/latest/
On that page you can find some lists of keyword names used in S*BASIC and various toolkits, so that you can choose variable, proc and fn names which don't clash with existing keyword names.
The SuperBASIC Reference Manual online is also very useful for this:
https://superbasic-manual.readthedocs.io/en/latest/
--
All things QL - https://dilwyn.theqlforum.com
All things QL - https://dilwyn.theqlforum.com
Re: Timer in SuperBasic?
Hi thanks for the encouragements, general Healthwise I’m doing OK
Timing is everything that and a little humour.
Once on safari I met an elephant in my pyjamas.
Dramatic Pause…
How it got into my Pyjamas I will never know!!!
This simple QBITS timer calls GTime at regular points in a programs events.
Initiate Timer GTS=0 : Gclk=DATE
DEFine PROCedure GTime
Gclk$=DATE$((DATE-Gclk+GTS
INK 7:CURSOR 400:10:PRINT Gclk$(13 to 20) 00:00:00 Hours : Minutes : Second
END DEFine
The four most important words in the English dictionary ‘Listen to your wife’.
You don’t have to always agree, but arguably disagree at your peril.….
QBITS
Timing is everything that and a little humour.
Once on safari I met an elephant in my pyjamas.
Dramatic Pause…
How it got into my Pyjamas I will never know!!!
This simple QBITS timer calls GTime at regular points in a programs events.
Initiate Timer GTS=0 : Gclk=DATE
DEFine PROCedure GTime
Gclk$=DATE$((DATE-Gclk+GTS
INK 7:CURSOR 400:10:PRINT Gclk$(13 to 20) 00:00:00 Hours : Minutes : Second
END DEFine
The four most important words in the English dictionary ‘Listen to your wife’.
You don’t have to always agree, but arguably disagree at your peril.….
QBITS
Re: Timer in SuperBasic?
I have tried the examples....
But I think it is still a pity that there seems not a precise sync timer in .01 or .001 seconds independent of the platform.
But I think it is still a pity that there seems not a precise sync timer in .01 or .001 seconds independent of the platform.