| | |
How to spead a loop?
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Sep 2009
Posts: 8
Reputation:
Solved Threads: 0
Hello to guys/girls on the forum. Question I have is following. How to speed this loop?
The loop is very slow. To generate 2,000,000 lines it needs 2:45 hours. As it continues, it gets slower and slower still.
Any help to this problem of mine is greatly appreciated.
Regards,
marygreen
Pascal and Delphi Syntax (Toggle Plain Text)
begin var i:integer; begin for i:=1 to 9999999 do begin //do something Memo1.Lines.Add ((floattostr(a1.value))+' + '+(floattostr(a2.value))+' + '+(floattostr(a3.value)); //do something Memo1.Lines.Add ((floattostr(a1.value))+' + '+(floattostr(a2.value))+' + '+(floattostr(a3.value)); //do something Memo1.Lines.Add ((floattostr(a1.value))+' + '+(floattostr(a2.value))+' + '+(floattostr(a3.value)); Application.ProcessMessages; if GetKeyState(VK_Escape) AND 128 = 128 then break; end; end;
The loop is very slow. To generate 2,000,000 lines it needs 2:45 hours. As it continues, it gets slower and slower still.
Any help to this problem of mine is greatly appreciated.
Regards,
marygreen
Is it required to see those lines as they are generated. If you could send them to a file, you can speed it up. The memo is really awful for this amount of data.
Also, the processmessages slows things down. You could call it every 100 loops instead for example.
In the Lines.Add you use floattostr three times. Have a look at the Format() function.
Also, the processmessages slows things down. You could call it every 100 loops instead for example.
In the Lines.Add you use floattostr three times. Have a look at the Format() function.
"If it is NOT source, it is NOT software."
-- NASA
-- NASA
•
•
Join Date: Sep 2009
Posts: 8
Reputation:
Solved Threads: 0
Pitaeas,
Thank you for answering. Indeed, I tried to send lines to a file with this:
But the loop is even slower than with memo option.
Format function is new for me, I’ll look into it.
Thank you for answering. Indeed, I tried to send lines to a file with this:
Pascal and Delphi Syntax (Toggle Plain Text)
var keep : textfile; text : string; begin AssignFile(keep, 'c:\lines.txt'); ReWrite(keep); WriteLn(keep,(floattostr(avf1.value)),' + ',(floattostr(avf2.value), '+', (floattostr(avf2.value) )); CloseFile(keep); end;
But the loop is even slower than with memo option.
Format function is new for me, I’ll look into it.
"The loop is very slow. To generate 2,000,000 lines it needs 2:45 hours. As it continues, it gets slower and slower still."
I wrote a same program like yours.....
what if you leave out floattostr function from the loop?
button1 coded:
it takes 8 minute to me to accomplish...my processor is clear pentium 3000 mhz
I wrote a same program like yours.....
what if you leave out floattostr function from the loop?
button1 coded:
delphi Syntax (Toggle Plain Text)
procedure TForm1.Button1Click(Sender: TObject); var i:integer; s:string; begin s:=floattostr(3.14); for i:=1 to 2000000 do begin memo1.Lines.add(s); end; end;
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
•
•
Join Date: Sep 2009
Posts: 1
Reputation:
Solved Threads: 0
Most likely the delays deal with the memo box. Each time you add lines the list gets longer. Check the limits in you memo component and perhaps overwrite the handling of the memo field to change the update/display process.
Also, if the float conversions can be done beforehand (in the "do something else") you might increase the speed.
JNG
Also, if the float conversions can be done beforehand (in the "do something else") you might increase the speed.
JNG
![]() |
Similar Threads
- Excel 2007 - infinite code loop (Windows Software)
- help in stored procedure-result of a loop using cursor (MS SQL)
- Help with gui loop. (C)
- Loop...without the loop (Java)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: How can I write a program that writes to a text file?
- Next Thread: Help with a bunch of TImages
| Thread Tools | Search this Thread |





