Advertisement

Optimazation - Is it worth it

Started by July 13, 2001 04:55 PM
8 comments, last by GameChld 23 years, 7 months ago
now a days with the speed of processors, does modifying the math routine: int = int / power of 2, to a int = int << power of 2 really do anything to speed. even if it is done somewhere around 100 times a loop. not that i hae that many that i could do, but was wonderig if it was worth it to look around. thanks much Code makes the world spin round
Code makes the world spin round
Why make a program perform worse than it has to?

If you know a way to speed it up, speed it up.

Ben
http://therabbithole.redback.inficad.com



Advertisement
Quite frankly, that''s a silly question. If all apps running on your machine were written without a single consideration toward optimization, that processor speed would become irrelevant, right? So, any optimization you can make is worth it. Plus, don''t you want your stuff to be nice and slick?

By the way, in the example you chose, all [intelligent] compilers will convert division by powers of 2 to bit shifting automatically. If I recall correctly, it''s called "strength reduction," or some such thing.
Theoritically the compiler will do it anyway, but it''s good practice. Best not to rely on compiler when you dont need to
BetaShare - Run Your Beta Right!
Optimize. I repeat, Optimize. Unfortunatly, modern day programmers seem to be forgetting about it. It is true, proccessors are fast now. But, when lazy programmers don''t optimize, it wastes resources that could be used for something else. I have dos programs that out performe my new software, which should definatly NOT be the case.
Back in the day of limited resources, and slow proccessors, programmers were smart, and spent alot of time finding short cuts to speed things up, and use the least memory possible.
In case you couldnt'' tell, it really bothers me that programmers don''t optimize as much as they used to.
If my opinion doesn''t sway you, then let me just say in my last program I was working on, it did quite a bit of pixel ploting, and by removind ONE processor instruction per pixel, it sped it up by 100ms/frame on my 400 mhz celeron.
That is kind of an extreme example, but I also made a few smaller changes, that alone didn''t make much of a difference, but went from 40 fps (after the above, but before the smaller ones) to 50 fps. That''s a 10 fps jump, by small optimizations. Now I have extra speed to use for AI or just let me game run on a slower computer--widening my audience.

So, back to your question, yes, optimize. Optimize everyway you can. For that specific example, well, I think most compilers do that optimization for you to some extent, but if you get used to doing it yourself, you''d probably be better off.

WEll, that''s just my $.02 and a couple dollars more...



Drakonite

[Insert Witty Signature Here]
Shoot Pixels Not People
Just a note, I said most programmers are forgetting about optimizing, well, I was a little off. What I meant was, that most programmers don''t care, as they see that "the proccessor is plenty fast to handle it." and don''t worry that the user may have a dozen other programs running. Games are currently the one area of programming that I still see many people still making a large attempt at optimization, unfortunatly, it needs to be everyone on every type.



Drakonite

[Insert Witty Signature Here]
Shoot Pixels Not People
Advertisement
As someone mentioned, that example would be optimized by the compiler. As for optimizing in general, don''t do it until you have to. Write clean, easiliy readable code. Then if you have performance problems, profile the code and optimize where you need it. The bottlenecks will often show up where you don''t expect. Another factor is the game may run fast enough without much optimization. If you are not doing 3d, you have much more power than needed for any 2d on any halfway recent machine.


Jack
quote:
Original post by JackNathan
As for optimizing in general, don''t do it until you have to. Write clean, easiliy readable code. Then if you have performance problems, profile the code and optimize where you need

This is a very good point, when you are developing you engine, you probably don''t want to optimize some things, as it will be harding to work on your engine. However, even if you don''t have performance problems, you should still go back and optimize as much as possible.

JackNathan - I know you didn''t mean to only optimize if there were performance problems, but I just wanted to clarify so that no one thought that was what you meant.




Drakonite

[Insert Witty Signature Here]
Shoot Pixels Not People
Of course you should optimize. You shouldn''t have to ask that. A lot of people can afford big powerful machines with fast processors, but there is always going to be someone who doesn''t have a decent machine that will play your game. Also, do not optimize while you''re coding. This can make your code unreadable. Unless it is something small like changing multiplication to bit shift, always wait until after you finish a section of code or the project itself before optimizing. Unoptimized code is easier to modify. Most compilers will do many optizimations for you, but there''s no way you can be sure. And, if one compiler optimizes something while some others don''t, and you later port your code to a different compiler, you could have trouble on the new compiler if you didn''t optimize your code yourself.
Forget slow machines as a special case: that's not the reason to optimize. You optimize because you want to get as much out of the system as possible. And, again, if all programs running on your machine--including the operating system--weren't optimized to some degree, it'd slow the heck out of your whiz-bang processor.

Edited by - merlin9x9 on July 13, 2001 10:08:45 PM

This topic is closed to new replies.

Advertisement