Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C programming tricks

Name: Anonymous 2007-09-15 22:06 ID:WCtjqT0N

While programming optimization that makes ones' code completely unreadable is often a bad thing, there are places for it, like that one inner loop of your code that takes up 98% of the program's running time.

What are you tricks for improving performance in C, other than the obvious inline assembly or the like?

Name: Anonymous 2008-01-10 0:52

This is some C code I wrote this morning:

     int count = 0;
     int m = 0; /* Start with the first offset modifier. */
     for (m = 0; count<4 && m < 8; m++)
     {
          if (!m%2) count = 1; /* The count is for one of the four directions. */
          int xo = 0,yo = 0,i = 1; /* Offsets and incrementer. */
          for (;(x+xo>=0) && (x+xo<WIDTH)   /* Make sure we've not */
             && (y+yo>=0) && (y+yo<HEIGHT)  /* gone off the grid.  */
             && grid[x+xo][y+yo]==pl; /* Every single one needs to be ==pl. */
               i++, xo=i*mod[m].x, yo=i*mod[m].y, /* Update offsets. */
               count++);/* Increase count. */
     }

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List