Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Delphi-News aus aller Welt (https://www.delphipraxis.net/58-delphi-news-aus-aller-welt/)
-   -   How to accelerate 10 times the "For" loops with Delphi (https://www.delphipraxis.net/200941-how-accelerate-10-times-loops-delphi.html)

DP News-Robot 10. Jun 2019 10:00

How to accelerate 10 times the "For" loops with Delphi
 
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...


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:00 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz