jaclas

Const vs no const

Apr 21st, 2021
617
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. {$R *.res}
  6.  
  7. uses
  8.   System.Diagnostics,
  9.   System.SysUtils;
  10.  
  11. type
  12.   TRek = record
  13.     a : Int64;
  14.     b : Int64;
  15.     c : Int64;
  16.     d : Int64;
  17.     e : Int64;
  18.     f : Int64;
  19.     g : Int64;
  20.   end;
  21.  
  22. procedure Rek(aRek : TRek);
  23. var
  24.   l: Int64;
  25. begin
  26.   if aRek.a = 888 then Exit;
  27.   if aRek.b = aRek.a then Exit;
  28.   l  := aRek.a + aRek.c;
  29. end;
  30.  
  31. procedure Rek2(const aRek : TRek);
  32. var
  33.   l: Int64;
  34. begin
  35.   if aRek.a = 888 then Exit;
  36.   if aRek.b = aRek.a then Exit;
  37.   l  := aRek.a + aRek.c;
  38. end;
  39.  
  40. procedure Test;
  41. var
  42.   i: Integer;
  43.   lWatch : TStopWatch;
  44.   lRek : TRek;
  45. begin
  46.   lWatch := TStopWatch.Create;
  47.   lRek.a := Random(MaxInt);
  48.   lRek.b := Random(MaxInt);
  49.   lRek.c := Random(MaxInt);
  50.   lRek.d := Random(MaxInt);
  51.   lRek.e := Random(MaxInt);
  52.   lRek.f := Random(MaxInt);
  53.   lRek.g := Random(MaxInt);
  54.   lWatch.Start;
  55.   for i := 0 to 10000000 do
  56.   begin
  57.     Rek(lRek);
  58.   end;
  59.   lWatch.Stop;
  60.   Writeln('czas 1: ',  lWatch.ElapsedMilliseconds, ' ms');
  61.   lWatch.Reset;
  62.   lWatch.Start;
  63.   for i := 0 to 10000000 do
  64.   begin
  65.     Rek2(lRek);
  66.   end;
  67.   lWatch.Stop;
  68.   Writeln('czas 2: ',  lWatch.ElapsedMilliseconds, ' ms');
  69. end;
  70.  
  71.  
  72. begin
  73.   try
  74.    Test;
  75.    Readln;
  76.   except
  77.     on E: Exception do
  78.       Writeln(E.ClassName, ': ', E.Message);
  79.   end;
  80. end.
  81.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×