$new_guy:
A couple observations:
- You're reading a file inside a loop, so you can potentially read and discard it a large number of times. Perhaps it would be better to store the data and simply reuse it?
- You've got some nested loops: the number of times you execute the code in the innermost loop is typically the product of the number of iterations of each loop. So you need to:
- Remove nested loops when possible, and when it's not possible,
- move operations out of the innermost loop.
Of course, this is assuming that you've run the appropriate profiling tools and determined that the nested loops are your problem. (Don't optimize what isn't a problem.)
...roboticus
When your only tool is a hammer, all problems look like your thumb.