? Speed optimizations ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password
[Help Wanted] SmileBASIC Documentation Project

Speed optimizations

One problem with SB: speed. SB lacks speed. In this "tutorial" i will show you ways to make your code faster/more efficient

One example

Here is one example: DIM MAP[100,100] FOR I = 0 TO 99 FOR J=0 TO 99 MAP[I,J] = RND(100) NEXT NEXT or you can do this: DIM MAP[100,100] FOR CNT = 0 TO 99*99 I = FLOOR(CNT/99) J = CNT MOD 99 MAP[I,J]=RND(100) NEXT the reason why it is faster is because it is slower to make nested loops

DON'T BE LAZY!

instead of this: FOR I = 0 TO 20 PRINT I NEXT do this: PRINT 1 PRINT 2 PRINT 3 PRINT 4 PRINT 5 PRINT 6 PRINT 7 PRINT 8 PRINT 9 PRINT 10 PRINT 11 PRINT 12 PRINT 13 PRINT 14 PRINT 15 PRINT 16 PRINT 17 PRINT 18 PRINT 19 PRINT 20

another method

if you have a main loop(a game, for example) and you want to update the map inside of it, do this: DIM MAP[W,H] VAR I,J WHILE 1 'code and all that INC I IF J == H-1 && I==W-1 THEN I = 0 : J = 0 IF I==W-1 THEN INC J:I=0 DOSOMETHING I,J'do something to the map, like set it as an empty tile for BG WEND this method is going to update the map slowly, but it will not cause the main loop to have a low FPS

Use VSYNC conditionally

WHILE 1 M=MILLISEC IF B THEN CLS'AND OTHER STUFF B=!B 'DO SOMETHING IF MILLISEC-M>30.3030303 THEN VSYNC'30.3030303 milliseconds is 30 FPS. if fps is greater than 30,VSYNC to slow it down a bit WEND I will add more later
Author
DFrost
Updated
Rating
12 votes
Categories
Keywords
8 Comment(s) AnswerXOX AnswerXOX Great Page Hidden Achievements RNG Hidden Easter Eggs Second Year My account is over 2 years old Website are you trolling? MochaProbably MochaProbably Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies Dfrost i did testing with your methods. No nested FOR loops are faster (with both loops doing the equivalent of 1999*1999 nested was almost 100ms faster) And VSYNC can put any program at 30FPS consistently by using VSYNC 2. MochaProbably MochaProbably Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies - Dont be lazy - I will add more later hmm DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength lol Sam Sam Amazing Page Hidden Achievements Great Page Hidden Achievements Good Page Hidden Achievements this comment is why we need to be able to upvote comments lmao random_god random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Video Games I like to play video games! Hobbies lol x2 DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength DEF laugh OUT LOUD LOUD = POW(1000,1000)'returns inf END DEF LOL LAUGH OUT LOUD END LOL! DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength also, I was doing this in a pinch of time(like I am now)