Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Can you (would you) += in MMBasic
Page 3 of 4 | |||||
Author | Message | ||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9115 |
You are doing bit shifts on floating point numbers - yuk!!! |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1611 |
But: list Option explicit Dim integer a, n a=57 Timer=0 For n=1 To 10000 a=a<<1 Next Print Timer a=57 Timer=0 For n=1 To 10000 a=a*2 Next Print Timer > run 521 531 > '<<' is an integer function and when using integers it is a tiny bit faster. Plus the whole program runs a lot faster. Bill Keep safe. Live long and prosper. |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2075 |
@matherP - oops! @Turbo46 - yay! |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1611 |
Geoff, Peter's implementation of INC for the CMM2 et al has been quite successful and is used quite often now. Please see Tom's (thwill) Laser Cycle as an example. It IS more compact and faster than the normal BASIC method of incrementing a variable. Is it possible that you may look again at including it now in the Micrmites please? Bill Keep safe. Live long and prosper. |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
gcbasic can use a++ instead of a=a+1 a--- instead of a=a-1 but I don't do c |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1611 |
INC by Peter is quite versatile the value that you 'INC' by can be any number, positive or negative and even an expression. I like it. Bill Keep safe. Live long and prosper. |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
SUB INC k, d LOCAL delta IF d = 0 THEN delta = 1 ELSE delta = d k = k + delta END SUB delta=not d ... faster? Edited 2023-03-13 00:27 by stanleyella |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1109 |
k = k + d + (d = 0) Visit Vegipete's *Mite Library for cool programs. |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1611 |
Thank you Stan and Vegipete. I tried: SUB INC k, d k = k + d + (d = 0) END SUB Of course it worked just like the INC command does and would be useful if converting a program meant for another device to a Micromite. The point is though, it takes even longer to perform the operation than just doing it in line in the program: a = a + whatever As I understand it, the INC command performs the operation on the variable in situ rather than take a copy, manipulate it then then put it back. If that is wrong then I would be happy to be enlightened. Because Geoff seemed to seriously consider implementing it for the Micromite (and hopefully DOS) and because Peter has done so I was hoping that he will reconsider adding it. Bill Keep safe. Live long and prosper. |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 4040 |
This feels like one of those situations where some foolhardy soul gives an "informed" answer about an MMBasic internal only for Peter to point out how wrong they are ... I guess I will take one for the team . One significant reason is that to perform "INC x" the interpreter only looks up "x" once whereas for "x=x+1" it looks it up twice - variable lookup is an expensive operation. The former also only involves handling two tokens whereas the latter involves five. Best wishes, Tom Edited 2023-03-13 08:39 by thwill Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1611 |
Thanks Tom that makes sense. Bill Keep safe. Live long and prosper. |
||||
Martin H. Guru Joined: 04/06/2022 Location: GermanyPosts: 1113 |
Why are you using a SUB with the same Name as a Command that allready exists? 'no comment |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1611 |
The INC command exist for the Micromites or MMBasic for DOS. That is the point. Bill Keep safe. Live long and prosper. |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 4040 |
"The INC command [DOES NOT] exist for the Micromites or MMBasic for DOS. That is the point." Best wishes, Tom Edited 2023-03-14 19:51 by thwill Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1611 |
Oops. Thanks Tom. Bill Keep safe. Live long and prosper. |
||||
Martin H. Guru Joined: 04/06/2022 Location: GermanyPosts: 1113 |
Thanks Tom, that's what confused me. However, a call to a Function or Sub takes more time than the actual calculation. Mart!n 'no comment |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1611 |
Geoff, I wonder if you would reconsider adding the INC command to MMBasic for the Micromites and MMBasic for DOS? You did seem sort of amenable to the idea when it was first discussed here. With with the success and wide acceptance of Peter's implementation of the command for the CMM2 et al I was hoping you might. Unless I've done something stupid, a little test on my CMM2 shows that it is about twice as fast as the "a = a + 1" method. ' Test the difference the INC command makes ' ' Get the FOR NEXT loop time b = timer for i = 1 to 10000 next i t = timer - b print " Loop time: "; t ' ' INC time a = 1 b = timer for i = 1 to 10000 inc a next i c = timer - b - t print " INC time: ";c ' ' a + 1 time a = 1 b = timer for i = 1 to 10000 a = a + 1 next i c = timer - b - t print " a + 1 time: ";c > run Loop time: 15.441 INC time: 14.179 a + 1 time: 29.455 > The command does seem rock solid, fast and useful and as the code is available, I'm hoping you will think again. Please. Bill Keep safe. Live long and prosper. |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
look at vegipete's picorocks for non standard basic. proper? https://www.thebackshed.com/forum/ViewTopic.php?FID=16&TID=16568&LastEntry=Y#215827 |
||||
PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 859 |
Definitely a thing of beauty. No interest in games but I get a kick out of well-structured source code...yeah I'm weird |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
This really worries me. For a start I'm very much one for standards and INC is very much non standard. As far as I know, no other BASIC uses it so MMBasic will be (to a small amount) non standard. The other thing is that I have decided to leave the Micromite version of MMBasic as it is unless a major bug is found or a major feature is needed. This is because the firmware is quite stable and when I fiddle with it I tend to add bugs. Also, Peter has used it as the basis for all his implementations and a major change would cause him a load of work, or worse, a fork. However INC is relatively harmless so I will add it to the Micromite todo list, but I'm not sure when the next release would be. Geoff Geoff Graham - http://geoffg.net |
||||
Page 3 of 4 |
Print this page |