Einzelnen Beitrag anzeigen

Benutzerbild von DP News-Robot
DP News-Robot

Registriert seit: 4. Jun 2010
14.992 Beiträge
 
#1

How to accelerate 10 times the "For" loops with Delphi

  Alt 10. Jun 2019, 10:00
To get the for loops to run up to 10 times faster you have to use PPI (Parallel programming Library) and if you don't believe it, run the following code: loop for As usual: uses System. Threading,//Parallel programming Library System. Diagnostics; TStopwatch// ... Procedure TForm1. btnForLoopRegularClick (sender: TObject); var SW: TStopwatch; I: integer; begin SW: = TStopwatch. StartNew; For I: = 0 to 99 do Sleep (10); Sw. Stop Label1. Text: = SW. ElapsedMilliseconds. ToString + ' MS '; end; Now the same loop using PPIprocedure TForm1. btnForLoopParallelClick (sender: TObject); var SW: TStopwatch; I: integer; begin SW: = TStopwatch. StartNew; TParallel. For (0, 99, procedure (I: integer) begin Sleep (10); End); Sw. Stop Label1. Text: = SW. ElapsedMilliseconds. ToString + ' MS '; end; In the first case the execution time is 1038 Msegs and in the second case of 117 Msegs., as you see the speed increase is in a range of 10 times approximately. I hope this Truc

Weiterlesen...
  Mit Zitat antworten Zitat