Main forum > GLBasic - en

speeding up mathematical operations?

(1/2) > >>

svenart:
Hey everyone.

I´m working on a Binary puzzlegame and the puzzles are generated. Generating a puzzle at a playfield of 6x6 squares takes only 1-2 seconds or less.
But when I generate at 8x8 squares, It takes 20-30 seconds, which is a nogo  :'(

So I´m asking if there is generally a way to speedup mathematical operations.
Are there any tricks, or slow commands I should stay away from?
Should I use more integer variables to speed it up ?
Should I use repeat/until instead of while/wend?
Is there someting faster than mod command maybe?
Anything else I should be aware of?

Any help would be greatly appreciated.

Moru:
Hard to say without playing around with the code and I can't really read the screenshot, too small text :-)

Most slow things I have seen in GL Basic has been when working with arrays that needs resizing so try to always create the arrays the size you need. But the arrays you use seems to be very small so should not be a problem. The arrays I was running that had problems with speed was more than a million lines and were pretty fast still.

There is a profiling function in the IDE that tells you what function is causing the slowest times, maybe there is a loop that is running more than you think? 20-30 seconds for such a small array sounds way too much unless you have a very old computer?

erico:
Since computers nowadays are ridiculously fast compared to 8bit, this issue should not be a problem unless you are dealing with really huge amounts of data or very complex calculations.
Anyways, what Moru said is the best answer, you can use the profiler to check that.

dreamerman:
As GLB code is converted to C++ it is quite fast, only minor overhead is added, so all general optimization advice applies here to.
Use integers% rather than floats#, don't do redundant calculations, use arrays with static size - don't do DimPush DimDelete or use more sophisticated code to detect when array should be resized, use Alias when excessive using array element in loops, if can use 1-dimensional arrays instead 2/3d, SIN/COS can be replaced with pre-calculated values/faster versions. hm, that most that I can remember. And as said GLB is fast enough to calculate complex algorithms in realtime like hundreds of A* pathfinding, AABB collisions, random map generations, and so on, all depends on implementation and as other said it's hard to tell something without seeing the code, even small bug/design choice can sometime give unpredictable result.

Ian Price:
It shouldn't be slow at all - I generated 9x9 puzzles for my 2016 Sudoku WIP (LOL - no work, no progress!) in less than a second, which uses arrays and checking.

Unfortunately I no longer have GLBasic on my new laptop, so can't share the code.

Here's a link to the WIP though - https://socoder.net/?Topic=5728

I also did Towers and KenKen (Ken2X) games for the Palm Pre/Pixi etc. and they were fast too, even on limited hardware.


BTW I love those 1/0 puzzles. :D

Navigation

[0] Message Index

[#] Next page

Go to full version