Timer in SuperBasic?

Anything QL Software or Programming Related.
User avatar
NL_QL_Usr
Bent Pin Expansion Port
Posts: 95
Joined: Sun Jan 08, 2023 8:42 am
Location: Harz DE

Timer in SuperBasic?

Post by NL_QL_Usr »

I was searching for a usable timer in Superbasic...
Like Millis for Arduino for instances

Does Anyone know?


User avatar
tofro
Font of All Knowledge
Posts: 3132
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Timer in SuperBasic?

Post by tofro »



ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
NL_QL_Usr
Bent Pin Expansion Port
Posts: 95
Joined: Sun Jan 08, 2023 8:42 am
Location: Harz DE

Re: Timer in SuperBasic?

Post by NL_QL_Usr »

tofro wrote: Fri Jul 19, 2024 3:43 pm https://dilwyn.theqlforum.com/tk/timing.zip
WOW youre Fast!!!

and it looks exactly what I need Thanks!!! :D


stevepoole
Aurora
Posts: 890
Joined: Mon Nov 24, 2014 2:03 pm

Re: Timer in SuperBasic?

Post by stevepoole »

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 !
Code_Timer.zip
(585 Bytes) Downloaded 181 times


User avatar
NL_QL_Usr
Bent Pin Expansion Port
Posts: 95
Joined: Sun Jan 08, 2023 8:42 am
Location: Harz DE

Re: Timer in SuperBasic?

Post by NL_QL_Usr »

stevepoole 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.
Thanks Steve

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!!!


qbits
Gold Card
Posts: 261
Joined: Sun Dec 11, 2016 3:32 pm

Re: Timer in SuperBasic?

Post by qbits »

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


stevepoole
Aurora
Posts: 890
Joined: Mon Nov 24, 2014 2:03 pm

Re: Timer in SuperBasic?

Post by stevepoole »

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.
____________________________________


User avatar
dilwyn
Mr QL
Posts: 3117
Joined: Wed Dec 01, 2010 10:39 pm

Re: Timer in SuperBasic?

Post by dilwyn »

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/


qbits
Gold Card
Posts: 261
Joined: Sun Dec 11, 2016 3:32 pm

Re: Timer in SuperBasic?

Post by qbits »

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


User avatar
NL_QL_Usr
Bent Pin Expansion Port
Posts: 95
Joined: Sun Jan 08, 2023 8:42 am
Location: Harz DE

Re: Timer in SuperBasic?

Post by NL_QL_Usr »

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.


Post Reply