Jump to content
  • Advertisement
Sign in to follow this  
Nicholas Kong

How to write fast code without optimizing

This topic is 1615 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is fast code good or bad?

 

How to write fast code without optimizing?

 

I know I am not suppose to optimizing so I want to see if I can still write fast code.

 

Edit: Seriously, why the anonymous downvote...?

Edited by warnexus

Share this post


Link to post
Share on other sites
Advertisement

fast code is good and there is nothing wrong with optimizing your code, just don't waste too much time optimizing parts of your code that don't really matter.

 

The fastest code is code that you don't run.

Share this post


Link to post
Share on other sites

Just try to access your data in a linear fashion, which is cache friendly, like when reading or writing an array for example.

Also, most optimization i've done where just rethinking some algorithm an rewrite them in a more efficient manner.

Edited by Vortez

Share this post


Link to post
Share on other sites

Fast code first.

Optimization comes with repeating.

After a good deal repeating the solution of the same problem I could finish with both a fast and optimized code.

You can't reach this overnight.

Some techniques I needed to re-write from scratch around 5 or 10 times before grasping the best way to do it.

There were problems only after re-visiting it after a year I could get the idea behind some optimization technique.

So unless you have a good deal of time, you shouldn't try to optimize your code and only finish it.

Share this post


Link to post
Share on other sites

Who says you're not supposed to be optimizing? Just don't optimize things that don't matter. To know what matters, measure.

Oh I see.

Edited by warnexus

Share this post


Link to post
Share on other sites

Your code should be

 * clear

 * correct

 * fast

... in that order. Some people would place `correct' first, but I would rather have code that I understand even if it doesn't cover every conceivable case, as long as it is clear enough that I know immediately what the not-covered cases are.

 

Don't write stupid code that is needlessly slow, but don't obsess about performance until it's clear that the program is not fast enough. In that case, use your profiler to focus your efforts where you should.

What makes a code stupid? Unreadable code you mean?

Edited by warnexus

Share this post


Link to post
Share on other sites

 

What makes a code stupid? Unreadable code you mean?

 

 

 

stupid pseudo code:

 

For x = 0 to image_width

  For y = 0 to image_height

    Pixel(x, y) = 0

 

better version:

 

For y = 0 to image_height

  For x = 0 to image_width

    Pixel(x, y) = 0

 

Do you understand the difference between the two?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!