What's dragging me down?
BlitzMax Forums/BlitzMax Programming/What's dragging me down?
| ||
I wrote a falling sand game a good while back, and I recently got an idea to make one that's really fast. So I wrote this code, and it it's completely painfully slow. I'm not using anything but integer maths, and even then the great majority of the operations are logic-based. Yet it's horridly slow. Why? I thought it might just be the rendering, but it's not. Mouse wheel scrolls through the elements, left click places them Here's the code Parse.bmx And fsgtest.txt Note that any code pertaining to reactions is far from complete. |
| ||
Do you know how to benchmark your code? Time different sections to find the one that's being so slow, and then you know where to optimise. |
| ||
First glance, I see a lot of global variables (slow) and non-Int datatypes (slow, depending on use, as the compiler automagically converts non-Int numeric values to Int). |
| ||
Do you know how to benchmark your code? Time different sections to find the one that's being so slow, and then you know where to optimise. This is the first time I've run the code. |
| ||
replaced Flip with SetColor 0,155,55 DrawText(check.count(),0,0) SetColor 255,255,255 Flip Play a bit and you wil recognize how the global var check will get have more and more items in it. Processing 5000 objects in a list is no fun for your cpu... plotting each of them in 640x480 should be possible but avoid it if you are capable of. Another thing noteable: your code isn't working out of the box, needed to disable the framework-command as else max2d is missing and some other null objects will be around. bye MB |
| ||
The problem isn't the number of checks - it creates a ton of them to make sure nothing is missed, but a couple if statements in the next game loop ensure that the same coordinate is never checked twice even if it appears multiple times in the list, and that particles that have no reason to update won't. I'm wondering why it gets so crazy slow at only about 200 actual particle updates/frame. |