Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Performance optimization

Status
Not open for further replies.

hunghsun

Programmer
Aug 25, 2002
31
0
0
US
Hi,

Our research group is developing a performance analysis tool for parallel programming and I would like to see if I can get some feedback from you guys.

Basically, I would like to know the following when you, the programmer, goes through to optimize your code.
1. What is your approach in doing this?
2. What kind of things do you look for to check on the performance of your code
3. What kind of analysis (for example: load balancing) you use

I would appreciate if you guys can provide me with some feedback on these issues as well as any comments you have. Thanks in advance!

Hung-Hsun
 
> 1. What is your approach in doing this?
Well for a sequential program, I would consider this - Getting points 1 and 2 right go a long way.
After all, no amount of tweaking the code will ever rescue your bubble sort from being trounced by any half-decent quicksort.

> 2. What kind of things do you look for to check on the performance of your code
When the code is finished, I'd use a profiler to figure out where the actual hot-spots are.

--
 
Thanks. Anyone else got any input for me?
 
I normally just record the number of clocks elapsed between points and work on the one that takes the longest. If you just look at code, it is very difficult to tell which bits are executed most often. I've seen lots of people optimizing stuff that is only executed once.

I use a profiler if one is available but it normally takes a lot longer to learn how to use the profiler than to add a few printfs. Sometimes profiler output is quite misleading. For instance, in a database application that did a lot of hashing, most of the time was spent in the mod function. But that's just looking at the trees instead of stepping back and seeing the wood.

As mentioned earlier, choosing the right technique is everything. You could parse an expression by reading one character at a time and getting into a right mess on lookup tables or you could use simple state machines for parsing which have been around for 30 odd years.

My analysis is quite simple - draw a flow chart and pull the string straight.
 
All Data Possibilies
First, for every aspect of your program you must know the number of operations that are performed. The goal of course is to reduce the amount of operations to a minimum. You do this by testing every possible combination of approaches, by building a program(s) that does this comprehensive finite activity for you. This will give you the shortest distance between two points, well based upon how much research you put into the routines and whether or not every possibility has been compesated for in your programming.

Finite Times and All Data Possibilities
When differing times become an issue, then another program must find all the possibilities for differing times for a particular quality of data type. (i.e. quick memory vs. slow memory or network speed vs. pc speed).

I think that is the basic approach.
 
One of the techniques I like to employ is to build from efficient blocks. I create these blocks by trying lots of different ideas for the same piece of code and I time each concept to see which works best.

Example:
Code:
if(condition1) {
  return value1;
} elseif(condition2) {
  return value2;
} etc ...
It might seem initially like there is no other way to do this but with a bit of lateral thinking you can use the ternary (trinary?) operator:
Code:
return condition1 ? value1 : (condition2 ? value2 : etc ...

Trojan.


 
Looks like the #1 concern for everyone is time related (i.e. involve timing of something and trying to get the fastest time). Anyone ever try analyzing the code that doesn't involve time?

Hung-Hsun
 
One might look at memory usage issues for two reasons.
First, throughput and speed (as usual)
Second, you might be simply using too much for the task in question.
Generally though, throughput is the only real reason for optimisation.


Trojan.
 
> Anyone ever try analyzing the code that doesn't involve time?
Optimise for maintainability - like this solution is quick, but horrible to even look at, and this other solution is barely slower and is dead easy to read.
Read "The approximate value of an optimization is: " at the end of my previous link.

Or what about optimising for power consumption?
If you're writing for mobile devices, then choosing approaches with preserve battery life are important.

Or what about patents - do you use this fast (but patented and expensive to licence approach), or something slower and in the public domain?

--
 
>>> Anyone ever try analyzing the code that doesn't involve time?

--- No - have you ?!!! Analysing code takes time, and I seriously doubt that any "code analyser" could really iron out every single bug/performance problem. Which means that someone still has to go through the code by hand if they wish to "analyse" it ...

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top