Home » General Computing

Code Optimization

1 June 2008 No Comment

My co-worker Marc’s got a good post on code optimization[LINK]; I couldn’t agree more in this case.

I think programmers should be given a mandatory course in games programming and/or embedded systems. One of my first jobs out of college was programming a home-grown smartcard reader for the CAROLAN project [LINK]. Can’t believe I found that link. I worked on this for 3 weeks in a tiny shop above a bakery in Rathmines. There was myself and one other guy, the electrical engineer who was busy soldering up boards on the other side of the room. It was a lot of fun.

I’ve written a few game-type things back in the day, the Maze of Madness[LINK], Dungeon of Death[LINK], Gloop[LINK] and so on.  Essentially you can’t get good frame-rates without a little optimization.

One thing I hear commonly is that optimization is something that was easier in the "OLD" days of C, C++ and Assembler. I’d challenge this with an example I wrote recently in C#. It’s a thing that creates collages/mosaics using the Discrete Cosine Transform [LINK]. the basic steps are as follows:

a) Gather images from Flickr
b) For each image, compute the DCT, storing the largest components of the transform along with their positions.
c) Take an input image and split it into sample areas.
d) For each sample area, compute the DCT vector.
e) Scan the database of DCT vectors to find the closest match using the Root Mean Square [LINK]
f) Place the highest scoring image in the sample area and move on…

This is a neat little application and as you can see quite CPU intensive with MANY places for optimization. Nevertheless, after gathering a database of over 35,000 images, the application takes roughly 1 second PER sample area when computing the best target image. This is after much optimization.

As you can see, C# is a powerful language with many conveniences and advanced constructs to make programming easier. That said, it’s ALSO possible to perform a lot of optimization, without the use of assembler or C.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.