![]() |
Small Basic super slow ?? - Printable Version +- Small Basic Forum (https://litdev.uk/mybb) +-- Forum: Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=1) +--- Forum: Standard Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=2) +--- Thread: Small Basic super slow ?? (/showthread.php?tid=385) |
Small Basic super slow ?? - Elzaimer - 06-04-2025 Hello everybody, I found this QBASIC program on Facebook : DIM SHARED pi, r, t, u, v, x DIM i AS INTEGER, j AS INTEGER DIM px AS INTEGER, py AS INTEGER DIM rr AS INTEGER, gg AS INTEGER, bb AS INTEGER SCREEN 12 RANDOMIZE TIMER pi = 4 * ATN(1) r = 2 * pi / 235 t = 4 * RND x = 0: u = 0: v = 0 CLS FOR i = 0 TO 249 FOR j = 0 TO 249 u = SIN(i + v) + SIN(r * i + x) v = COS(i + v) + COS(r * i + x) x = u + t px = INT(320 + 108 * u) py = INT(240 + 108 * v) IF px >= 0 AND px < 640 AND py >= 0 AND py < 480 THEN rr = (i * 3) MOD 256 gg = (j * 3) MOD 256 bb = (255 - (i + j) \ 2) MOD 256 LINE (px, py)-(px + 1, py + 1), _RGB(rr, gg, bb), BF END IF NEXT j NEXT i SLEEP I tried it on https://qbjs.org/ and as it was nice I converted it to Small Basic (PSGZ709.000) to compare the performances. The difference is incredible : 6 seconds on SB and less than a second on QBJS. Somebone has an explanation ? is my convertion bad ? is there a way to get better performances ? Would Svb be faster ? RE: Small Basic super slow ?? - martmen - 06-05-2025 Hello Elzaimer, the comparison may not be entirely fair since different hardware was used. Small Basic is designed to be as simple as possible. There is no need to define data types for variables. Small Basic uses only a single basic data type for all variables, which leads to performance disadvantages. Best regards, Martin Translate with capilot RE: Small Basic super slow ?? - AbsoluteBeginner - 06-05-2025 (06-04-2025, 08:39 PM)Elzaimer Wrote: ... (translated by Google translator) Small Basic is the LEGO of programming. ![]() Small Basic is optimized for learning and entertainment. People who want to "fly faster than sound" are doomed to study the F-35 for many years. RE: Small Basic super slow ?? - litdev - 06-05-2025 Your code is fine, it is SB that is slow. In some ways that is the charm - reminding me of early days using ZX Spectrum where you had to code very carefully to be efficient. It is mainly slow because it has a single type (Primitive) that is inernally checked and converted to required types, it also uses reflection to pass data. Internal data is stored in Dictionaries (e.g. Controls, Shapes, Images etc) that are indexed by a Primitie name, lookup is slow if there are lots of these. SB Arrays are especially slow since they are converted between string representations of Dictionaries internally. sVB uses pretty much the same compiler and command libarary with a few syntax changes. Arrays are usually the biggest culprit and extensions can be used to store data in Arrays and Lists. For example if we look at the SB code for GraphicsWindow.DrawLine: Code: GraphicsWindow.VerifyAccess(); VerifyAccess does some checks that the GraphicsWindow is there BeginInvoke runs the command as a delegate on the GraphicsWindow thread drawingContext is created and appended to the current list of drawings made DrawLine draws the line to the drawingContex Close closes the context AddRasterizeOperationToQueue looks at the size of the current series of drawing contexts in _mainDrawing and if ithere are more than 100, then it takes those 100 draw commands and redraws them to a bitmap that is then rendered to the background and _mainDrawing is reset ready for the next set of draw commands If we look at GraphicsWindow.GetColorFromRGB: Code: int num = Math.Abs(red % 256); The color is stored as a string "#RRGGBB" - every time this color is used it needs to be converted to the internal color type Every If comparison has to first work out whether the variables should be treated as numbers or strings. In a modern language each variable has a specific type and the compiler won't let you do inappropriate things. In SB this is all done at runtime, so for example we can add a number to a string and get concatenation or addition depending on whether the string can be interpreted as a number. Checks for this are done all the time, every operation on data needs to check what the type of the data might actually be. TextWindow.WriteLine("24.5"+2) TextWindow.WriteLine("X24.5"+2) RE: Small Basic super slow ?? - Elzaimer - 06-05-2025 ok ok... So now I'm now wondering if I should give a try to QB64. But do I need to make faster programs ? hummm...? It makes me crazy because I love the Small Basic's IDE, it's nice functions, and it's IntelliSense (I read somewhere that QB64 with VScode works well for this) ? or should I try to learn Python... And would it be faster... Oulala ! (I'm french) ?? RE: Small Basic super slow ?? - litdev - 06-05-2025 Ha ha, Dabble in them all. It depends what your motivation is: have fun, learn something, create a killer program, perform a specific task. Once you have basics (SB is great for that) then you see the limitations and why other languages are different, you will appreciate the additional complexities that give you more power and control. Mostly for LD extension I use Visual Studio with C#. At work its C#, C++ and Fortran! I recently played with Android studio and Kotlin for Android, and more recently VS Code with MonkeyC for Garmin devices. All similar but have their own quirks and fun to tinker with. All have a learning curve, but it gets shallower to more you do it. Have fun! RE: Small Basic super slow ?? - z-s - 06-06-2025 I am learning zig nowadays RE: Small Basic super slow ?? - sm4llprogrammer2008 - 06-07-2025 This led me to think of making SB on C++ to make it faster RE: Small Basic super slow ?? - litdev - 06-07-2025 (06-07-2025, 02:54 PM)sm4llprogrammer2008 Wrote: This led me to think of making SB on C++ to make it faster The SB compiler is written directly in IL. What makes it slow are the features it has like universal type - if it didn't have these simplifying features it could be faster, but wouldn't be Small Basic. Not everything is about speed - writing good maintainable code is the most important. Most compiled languages (C#, C++ and all the others have comparable execution speed), performance differences are in the programmer skill. RE: Small Basic super slow ?? - sm4llprogrammer2008 - 06-07-2025 Yep, plus QBJS runs on a JS engine which converts JS code to machine code, like V8. Plus SB runs on .NET, but JS engines might be slower sometimes. |