1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132:
| program Test;
{$APPTYPE CONSOLE}
uses SysUtils, Windows, Classes, Math; const cCount = 10000000; cTestAnz = 20;
var Test: Integer; MinZeit, MaxZeit, ZeitSum, Zeit, Freq: Int64; I: Integer; Anz: Integer; function WriteLnTest: Int64; var Start, Ende: Int64; F: TextFile; I: Integer; Text: string; begin QueryPerformanceCounter(Start); AssignFile(F, 'C:\Test.dat'); try Rewrite(F);
for I := 1 to cCount do begin Text := Format('Wert: %d', [I]); WriteLn(F, Text); if (I mod 100000) = 0 then Write(#13 + Format('Test %2d: ', [Test]) + FormatFloat('000%', (I / cCount) * 100)); end; finally CloseFile(F); end; QueryPerformanceCounter(Ende);
Result := (Ende - Start); end;
function StreamWriteTest: Int64; var Start, Ende: Int64; I: Integer; Stream: TFileStream; Text: string; begin QueryPerformanceCounter(Start);
Stream := TFileStream.Create('C:\TestSt.dat', fmCreate or fmShareExclusive); try for I := 1 to cCount do begin Text := Format('Wert: %d', [I]) + #13#10; Stream.WriteBuffer(Text[1], Length(Text)); if (I mod 100000) = 0 then Write(#13 + Format('Test %2d: ', [Test]) + FormatFloat('000%', (I / cCount) * 100)); end; finally Stream.Free; end; QueryPerformanceCounter(Ende);
Result := (Ende - Start); end;
begin try ZeitSum := 0; MinZeit := MaxLongint; MaxZeit := 0; Anz := 0;
QueryPerformanceFrequency(Freq);
WriteLn('WriteLn-Test'); for I := 1 to cTestAnz do begin Test := I; Zeit := WriteLnTest; ZeitSum := ZeitSum + Zeit; MinZeit := Min(MinZeit, Zeit); MaxZeit := Max(MaxZeit, Zeit);
WriteLn(#13 + Format('Test %2d: 100%%; Zeit: %g', [Test, Zeit/Freq])); Inc(Anz); end; WriteLn('----------------------------------------------'); WriteLn(Format('| Min : %g', [MinZeit/Freq])); WriteLn(Format('| Max : %g', [MaxZeit/Freq])); WriteLn(Format('| Avg : %g', [(ZeitSum/Anz)/Freq])); WriteLn('----------------------------------------------'); WriteLn;
ZeitSum := 0; MinZeit := MaxLongint; MaxZeit := 0; Anz := 0;
QueryPerformanceFrequency(Freq);
WriteLn('StreamWrite-Test'); for I := 1 to cTestAnz do begin Test := I; Zeit := StreamWriteTest; ZeitSum := ZeitSum + Zeit; MinZeit := Min(MinZeit, Zeit); MaxZeit := Max(MaxZeit, Zeit);
WriteLn(#13 + Format('Test %2d: 100%%; Zeit: %g', [Test, Zeit/Freq])); Inc(Anz); end; WriteLn('----------------------------------------------'); WriteLn(Format('| Min : %g', [MinZeit/Freq])); WriteLn(Format('| Max : %g', [MaxZeit/Freq])); WriteLn(Format('| Avg : %g', [(ZeitSum/Anz)/Freq])); WriteLn('----------------------------------------------'); WriteLn; WriteLn('Fertig'); except on E:Exception do Writeln(E.Classname, ': ', E.Message); end; ReadLn; end; |