Re: How to make Delphi code quicker
- From: "Ralf Mimoun" <nospam@xxxxxxxxx>
- Date: Fri, 2 Jun 2006 01:27:10 +0200
Valerij Rozouvan wrote:
....
Am I doing something wrong, or there
is simply no way to speed up Delphi code without
abandoning Delphi?
First and foremost: look at the algorithm! There is a time/space tradeoff. Means: you can get a lower time complexity by allowing a higher memory complexity. Roughly translated: buffers are great! Store anything you might need later, in the next iteration, whatever. Store everything that might be useful as a partial result of a calculation. If you are working with arrays: use helper arrays, one dimension smaller, for caching. Then go to the stranger parts: try different loops: for/next, while, repeat, count up or down. Try different data types, maybe you don't need integers everywhere and get better results by cramping more data in the level 1 cache. Don't address the same array element over and over again, instead push it in a variable. Of course, try to do the work in two or more threads! There are so many HT and dualcore CPUs today, it really helps. Most of the time :-)
And _then_, at the end: become a wizard. Go directly to the memory. Use pointers, increment them instead of addressing an array element with an index. Use Move, or better, FastMove. Take a look at the assembler code: any way to do something to give the compiler another register?
The last step can give you about 25%. BUT: the code becomes really ugly. And all the stuff before that can give 80% speed increase (eg. 20 seconds instead of 100). Once I had a contract to optimize a function that works an _really_ large arrays. I brought it down from about 40 seconds to .1 or so. One year later, I took fresh look, got another contract for the same thing, and now it's calculated in .02 seconds. And that means pattern recognition in an array with more than one million elements. But now I am pretty sure that there is nothing you can do while using Delphi to make it fast. Funny: for this function, a cheap Sempron 3100+ is almost as fast as a P4 3.2 HT...
Ralf
.
- References:
- How to make Delphi code quicker
- From: Valerij Rozouvan
- How to make Delphi code quicker
- Prev by Date: Re: How to make Delphi code quicker
- Next by Date: Re: How to make Delphi code quicker
- Previous by thread: Re: How to make Delphi code quicker
- Next by thread: Re: How to make Delphi code quicker
- Index(es):
Relevant Pages
|