Recent

Author Topic: Refference to Sin  (Read 2669 times)

Warfley

  • Hero Member
  • *****
  • Posts: 1762
Re: Refference to Sin
« Reply #15 on: November 29, 2024, 09:23:55 pm »
If the values are so closely together it's usually a sign that the overhead (in this case the for loop) is actually dominating the time. To alleviate this I changed it up a bit:
Code: Pascal  [Select][+][-]
  1.     // direct call
  2.     t1 := GetTickCount64;
  3.     for i := 1 to 10000000 do
  4.     begin
  5.       y := sin(i);
  6.       y := sin(i);
  7.       y := sin(i);
  8.       y := sin(i);
  9.       y := sin(i);
  10.     end;
  11.     Write(GetTickCount64 - t1, '           ');
  12.     // inline call
  13.     t2 := GetTickCount64;
  14.     for i := 1 to 10000000 do
  15.     begin
  16.       y := sin_(i);
  17.       y := sin_(i);
  18.       y := sin_(i);
  19.       y := sin_(i);
  20.       y := sin_(i);
  21.     end;
  22.     write(GetTickCount64 - t2, '          ');
  23.     // pointer call
  24.     t3 := GetTickCount64;
  25.     for i := 1 to 10000000 do
  26.     begin
  27.       y := MyFun(i);
  28.       y := MyFun(i);
  29.       y := MyFun(i);
  30.       y := MyFun(i);
  31.       y := MyFun(i);
  32.     end;
  33.     writeln(GetTickCount64 - t3);

Result:
Code: Text  [Select][+][-]
  1. direct call | inline call| pointer call|
  2. 1234           1344          1422
  3. 1234           1344          1422
  4. 1234           1344          1422
  5. 1234           1359          1407
  6. 1250           1375          1484

LV

  • Full Member
  • ***
  • Posts: 154
Re: Refference to Sin
« Reply #16 on: November 29, 2024, 10:11:19 pm »
Thank you, @Warfley.

Here is my configuration.

Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz   3.19 GHz
Lazarus 3.4 (rev lazarus_3_4) FPC 3.2.2 x86_64-win64-win32/win64
Optimization level: -(O1 + quick optimizations) (-O2)

The code above was used.

Results:

Code: Text  [Select][+][-]
  1. direct call | inline call| pointer call|
  2. 1422           1359          1375
  3. 1360           1375          1359
  4. 1375           1360          1359
  5. 1375           1359          1360
  6. 1390           1360          1343
  7. 1360           1375          1344
  8. 1375           1359          1359
  9. 1375           1375          1360
  10. 1390           1375          1344
  11. 1375           1359          1360
  12.  

 :(

 

TinyPortal © 2005-2018