![]() |
Format-Funktion zu langsam
Für eine simulation muss ich eine 200x200x200=800.000 Werte in einer Textfile speichern. Dazu ruf ich 800.000 mal die Format-Funktion auf:
Delphi-Quellcode:
Das dauert aber ELEND lange... Gibts da nicht eine Methode, die da wesentlich schneller arbeitet... FloatToStr bringt mir auch nix.
format('%.4f ',[C[Nr]]) ;
|
Re: Format-Funktion zu langsam
Hi,
evtl. ist Str() schneller..? Gruß Stephan :dance: |
Re: Format-Funktion zu langsam
Zitat:
Unabhängig davon, sind ca. 13 Sekunden für 8Mio Werte wirklich zu viel?
Delphi-Quellcode:
...:cat:...
procedure TForm1.Button1Click(Sender: TObject);
var Start, Stop, Freq: Int64; I: Integer; Id: Double; begin QueryPerformanceCounter(Start); for I := 1 to 8000000 do begin Id := I; Format('%.4f', [Id]); end; QueryPerformanceCounter(Stop); QueryPerformanceFrequency(Freq); Label1.Caption := Format('%f ms', [(Stop - Start) * 1000 / Freq]); end; |
Re: Format-Funktion zu langsam
Zitat:
Daneben gibt es noch: FloatToStrF und FloatToDecimal & FloatToText |
Re: Format-Funktion zu langsam
Zitat:
Zitat:
|
Re: Format-Funktion zu langsam
Zeig mal den Code drumherum.
|
Re: Format-Funktion zu langsam
Zitat:
Delphi-Quellcode:
Variante 1 : 5.671 ms
procedure TForm1.Button1Click(Sender: TObject);
var Start, Stop, Freq: Int64; ndx : Integer; sl : TStringList; Id: Double; begin QueryPerformanceCounter(Start); sl := TStringList.Create; try for ndx := 1 to 8000000 do begin Id := ndx; // sl.Add (FloatToStr (id)); // Variante 1 // sl.Add(Format('%.4f', [Id])); // Variante 2 sl.Add(FormatFloat('########.0000',ID)); // Variante 3 end; QueryPerformanceCounter(Stop); QueryPerformanceFrequency(Freq); Label1.Caption := Format('%f ms', [(Stop - Start) * 1000 / Freq]); sl.SaveToFile('c:\liste3.txt'); finally sl.Free; end; end; Variante 2 : 7.143 ms Varinate 3 : 7.657 ms |
Re: Format-Funktion zu langsam
Zitat:
Delphi-Quellcode:
Die Add Methode... FS ist ein TFileStream:
{ 3D-Matrix mit Parametern }
for Nr := 1 to 2 do begin for iz := 0 to G.z-1 do begin V_line[Nr] := format('%s (:,:,%d) = [',[A[Nr],iz+1]) ; for ix := 0 to G.x-1 do begin for iy := 0 to G.y-1 do with Thread.Cells[ix,iy,iz] do begin V_line[Nr] := V_line[Nr] + FloatToStrF (C[Nr],ffFixed,7,4) + ' ' ; // langsam, heisst ung. 20 min. //V_line[Nr] := V_line[Nr] + '0.0001 ' ; // schnell, par Sekündchen if (iy = G.y-1) and (ix < G.x-1) then begin V_line[Nr] := V_line[Nr] + '; ' ; end ; end ; end ; V_line[Nr] := V_line[Nr] + '] ;' ; Add (V_line[Nr]) ; V_line[Nr] := '' ; end ; Add ('') ; end ;
Delphi-Quellcode:
An der Add Methode kanns aber meiner Ansicht nach nicht liegen, da die ja auch aufgerufen wird, wenn ich Format weglasse, und direkt einen Wert schreibe.
procedure TMCBasisExport.Add(AText: string);
var buf : string ; begin if FS <> nil then begin buf := AText+#13#10 ; FS.Write(buf[1],length(buf)) ; end else begin raise exception.Create('Datei kann nich beschrieben werden.'); end ;end; |
Re: Format-Funktion zu langsam
[quote="Jelly"]
Delphi-Quellcode:
Deine Auskommentierung ist nicht fair, da du den Zugriff auf das Array C[] nicht berücksichtigt:
{ 3D-Matrix mit Parametern }
for Nr := 1 to 2 do begin for iz := 0 to G.z-1 do begin V_line[Nr] := format('%s (:,:,%d) = [',[A[Nr],iz+1]) ; for ix := 0 to G.x-1 do begin for iy := 0 to G.y-1 do with Thread.Cells[ix,iy,iz] do begin V_line[Nr] := V_line[Nr] + FloatToStrF (C[Nr],ffFixed,7,4) + ' ' ; // langsam, heisst ung. 20 min. //V_line[Nr] := V_line[Nr] + '0.0001 ' ; // schnell, par Sekündchen
Delphi-Quellcode:
// Variante 1
V_line[Nr] := V_line[Nr] + FloatToStrF (C[Nr],ffFixed,7,4) + ' ' ; // Variante 2 (ohne FloatToStrF) dummy_float := C[Nr]; // optimierung des compilers ausschalten, sonst wird wegoptimiert // und da da Array C[] wohl zu Thread.cells gehört, wird dies wohl die Hauptursache // für dein Performanceproblem sein !!! V_line[Nr] := V_line[Nr] + '0.0001 ' ; |
Re: Format-Funktion zu langsam
@shmia: hättest du Recht haben können... Habs aber grad getestet, und das ändert aber nichts am Verlauf :gruebel:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:07 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz