Einzelnen Beitrag anzeigen

Benutzerbild von nailor
nailor

Registriert seit: 12. Dez 2002
Ort: Karlsruhe
1.989 Beiträge
 
#6

Re: Seltsame Berechnung mit <sizeOf>

  Alt 20. Aug 2004, 13:08
es wird voraussichtlich langsamer. aber nicht so schrecklich viel.

edit:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TLevelSize = record
    Width : Int64; // 8 Bytes
    Height: Word; // 8 Bytes
  end;

  type
  TLevelSize2 = packed record
    Width : Int64; // 8 Bytes
    Height: Word; // 8 Bytes
  end;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
const max = 10000;
var i,j: integer; t: cardinal; a: array[0..max] of tlevelsize; b: array[0..max] of tlevelsize2;
begin
{$O-}
t:= gettickcount;
for i := 0 to max do
begin
for j := 0 to max do begin
a[i].Width := 0;
a[i].Height := 0;
end; end;
showmessage(inttostr(gettickcount - t));
t:= gettickcount;
for i := 0 to max do
for j := 0 to max do begin
begin
b[i].Width := 0;
b[i].Height := 0;
end; end;
showmessage(inttostr(gettickcount - t));
end;

end.
sorry für scheiss formatierung. aber in dem fall sinds ca 30% verlust. wenn man die arrays wegmacht, und immer auf dem gleichen record rumschreibt, dann gehts in der packed version sogar schneller.
Michael N.
http://nailor.devzero.de/code/sharpmath/testing/ --- Tests, Feedback, Anregungen, ... aller Art sehr willkommen!
::: don't try so hard - it'll happen for a reason :::
  Mit Zitat antworten Zitat