Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Optimizing code

Author
Message
Static
20
Years of Service
User Offline
Joined: 4th Apr 2004
Location: United Kingdom
Posted: 15th Jun 2004 23:23
Optimizing code is an important part of programming and is often neglected. It’s all very well to know how to write a program but if you’re getting a low FPS then things are not good for all those not with the latest computer. I feel that a lot of people don’t know how to optimize their code (me included) so I want this post to help people in doing so (especially the newbies). Please help the community by posting your optimizing secrets here. Also DB classic and DB pro are very different so you must say which version your post applies for.

Thanks for all ideas
Julian
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 15th Jun 2004 23:40
I was just wondering about this as well... as I was writing my 50th y = y + 1 line. I thought, is the INC command better? Faster? And so on...

Any truly great code should be indisguishable from magic.
Static
20
Years of Service
User Offline
Joined: 4th Apr 2004
Location: United Kingdom
Posted: 16th Jun 2004 00:14
In DBpro INC variable1,other variable seems to run at the same speed as variable1 = variable1 + other variable though INC is often shorter to write. As fo DB classic i don't know. You can check using the Screen FPS() command.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 16th Jun 2004 01:19
thanks, I may have to try that ....

Any truly great code should be indisguishable from magic.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 16th Jun 2004 03:28
I'll have to run a comparison to test it in DB & DpBro, but an old technique in optimization was to unroll loops. Although it's easier to type for x=1 to 100; blah; next x: the overhead (pushes & pops from the stack) and jump calls at the assembly level would cause a performance hit. I haven't looked at DB's assembly output to see what types of low level optimizations are built in.

Some low level optimizations that you will see still in use.
-Bit shifts for multiplication
-Using a lookup table for sin, cos, tan rather than carrying out real-time float computations.
-Working with 32-bit values


But I gather you are looking for optimizations that are not as archaic or low-level as this, and rather commands in DB like.
1) lock pixels
2) set sprite restore transparency to off
3) fastsync instead of sync
4) loading from memblocks
5) undimensioning unused resources


Much of what I've learned, or information I have, with regard to optmization isn't as relevant now as compilers have gotten better at optimizing the machine code, and as processing speed as increased dramatically. I haven't dug too far under the hood of DB/DBpro. Though I know that others have and made use of coding their own functions via plugins(dll's).

Still all the optimizations in the world couldn't save me from poor algorithms and design of my solutions to problems. That's where most of my slow-down comes from these days. Sometimes it's all in a solutions approach.


Static
20
Years of Service
User Offline
Joined: 4th Apr 2004
Location: United Kingdom
Posted: 16th Jun 2004 10:09 Edited at: 16th Jun 2004 10:12
I'm using DBpro and tried changing sync to fastsync in one of my games and got the same FPS. Yeah you're right about getting rid of unused ressources escpicaly levels or models with high polys. Oh and thats some other advice. Keep your models low poly!
Kentaree
21
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 16th Jun 2004 13:03
Most of the repetetive structures like do...loop and while...endwhile have built in checking which slows the loop down. The for loop has had this check removed so it is slightly faster. The push and pop wouldnt cause all that much more overhead to be honest, because in other kinds of loops the same will have to be done, if just with the memory address of the start of the loop, and they all would use something like jump anyway.

Also, apparently using sync in DBP can slow it down a bit. Try this and compare the results:





Its not a bug, its a feature!
Static
20
Years of Service
User Offline
Joined: 4th Apr 2004
Location: United Kingdom
Posted: 16th Jun 2004 16:10
Yes programs tend to run a slight bit faster without sync on but it depends alot on the computer. With a fast computer you won't notice the difference much but with a less powerful one you will. Also to speed things up
disable escapekey
backdrop on
do
if escapekey()=1 then end
print screen fps()
loop
Static
20
Years of Service
User Offline
Joined: 4th Apr 2004
Location: United Kingdom
Posted: 16th Jun 2004 16:40 Edited at: 16th Jun 2004 16:42
Most of the time in DBpro using functions is faster than using labels (and more practical) using Function instead of gosub is a good habit.
SCI_CO
20
Years of Service
User Offline
Joined: 20th Apr 2004
Location: USA
Posted: 19th Jun 2004 07:07 Edited at: 28th Jul 2004 08:32
DELETE IT
Static
20
Years of Service
User Offline
Joined: 4th Apr 2004
Location: United Kingdom
Posted: 19th Jun 2004 15:13
Interesting I got 133 FPS with this code:


then 66 FPS as i expected with this code:


I also got 66 FPS with this code:


I'm intrested to know why I get 133 in the first example.
Thanks SCI_CO for pointing this out.
Emperor Baal
20
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 19th Jun 2004 18:18
lol, why dont you multiply it?



SCI_CO
20
Years of Service
User Offline
Joined: 20th Apr 2004
Location: USA
Posted: 19th Jun 2004 22:29 Edited at: 28th Jul 2004 08:31
[DELETE ME]
SCI_CO
20
Years of Service
User Offline
Joined: 20th Apr 2004
Location: USA
Posted: 20th Jun 2004 00:13 Edited at: 28th Jul 2004 08:31
DELETE ME
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 20th Jun 2004 01:46
It's a known problem, only call SCREEN FPS() once between syncs.
http://www.thegamecreators.com/?m=forum_view&t=14797&b=15

can i scream
SCI_CO
20
Years of Service
User Offline
Joined: 20th Apr 2004
Location: USA
Posted: 20th Jun 2004 04:38 Edited at: 28th Jul 2004 08:30
DELETE

Login to post a reply

Server time is: 2024-09-22 14:26:43
Your offset time is: 2024-09-22 14:26:43