1515use PhpBench \Attributes \BeforeClassMethods ;
1616use PhpBench \Attributes \Iterations ;
1717use PhpBench \Attributes \ParamProviders ;
18- use PhpBench \Attributes \Revs ;
1918use RuntimeException ;
2019
2120use function array_chunk ;
4443#[AfterClassMethods('afterClass ' )]
4544#[AfterMethods('afterIteration ' )]
4645#[Iterations(1 )]
47- #[Revs(1 )]
4846final class ParallelMultiFileExportBench
4947{
5048 public static function beforeClass (): void
@@ -74,15 +72,15 @@ public function afterIteration(): void
7472 * Using a single thread to export multiple files.
7573 * By executing a single Find command for multiple files, we can reduce the number of roundtrips to the server.
7674 *
77- * @param array{chunk :int} $params
75+ * @param array{chunkSize :int} $params
7876 */
7977 #[ParamProviders(['provideChunkParams ' ])]
8078 public function benchSequential (array $ params ): void
8179 {
82- foreach (array_chunk (self ::getFileNames (), $ params ['chunk ' ]) as $ i => $ files ) {
80+ foreach (array_chunk (self ::getFileNames (), $ params ['chunkSize ' ]) as $ i => $ files ) {
8381 self ::exportFile ($ files , [], [
84- 'limit ' => 5_000 * $ params ['chunk ' ],
85- 'skip ' => 5_000 * $ params ['chunk ' ] * $ i ,
82+ 'limit ' => 5_000 * $ params ['chunkSize ' ],
83+ 'skip ' => 5_000 * $ params ['chunkSize ' ] * $ i ,
8684 ]);
8785 }
8886 }
@@ -103,12 +101,12 @@ public function benchFork(array $params): void
103101 Utils::reset ();
104102
105103 // Create a child process for each chunk of files
106- foreach (array_chunk (self ::getFileNames (), $ params ['chunk ' ]) as $ i => $ files ) {
104+ foreach (array_chunk (self ::getFileNames (), $ params ['chunkSize ' ]) as $ i => $ files ) {
107105 $ pid = pcntl_fork ();
108106 if ($ pid === 0 ) {
109107 self ::exportFile ($ files , [], [
110- 'limit ' => 5_000 * $ params ['chunk ' ],
111- 'skip ' => 5_000 * $ params ['chunk ' ] * $ i ,
108+ 'limit ' => 5_000 * $ params ['chunkSize ' ],
109+ 'skip ' => 5_000 * $ params ['chunkSize ' ] * $ i ,
112110 ]);
113111
114112 // Exit the child process
@@ -133,21 +131,21 @@ public function benchFork(array $params): void
133131 /**
134132 * Using amphp/parallel with worker pool
135133 *
136- * @param array{chunk :int} $params
134+ * @param array{chunkSize :int} $params
137135 */
138136 #[ParamProviders(['provideChunkParams ' ])]
139137 public function benchAmpWorkers (array $ params ): void
140138 {
141- $ workerPool = new ContextWorkerPool (ceil (100 / $ params ['chunk ' ]), new ContextWorkerFactory ());
139+ $ workerPool = new ContextWorkerPool (ceil (100 / $ params ['chunkSize ' ]), new ContextWorkerFactory ());
142140
143141 $ futures = [];
144- foreach (array_chunk (self ::getFileNames (), $ params ['chunk ' ]) as $ i => $ files ) {
142+ foreach (array_chunk (self ::getFileNames (), $ params ['chunkSize ' ]) as $ i => $ files ) {
145143 $ futures [] = $ workerPool ->submit (
146144 new ExportFileTask (
147145 files: $ files ,
148146 options: [
149- 'limit ' => 5_000 * $ params ['chunk ' ],
150- 'skip ' => 5_000 * $ params ['chunk ' ] * $ i ,
147+ 'limit ' => 5_000 * $ params ['chunkSize ' ],
148+ 'skip ' => 5_000 * $ params ['chunkSize ' ] * $ i ,
151149 ],
152150 ),
153151 )->getFuture ();
@@ -160,13 +158,9 @@ public function benchAmpWorkers(array $params): void
160158
161159 public static function provideChunkParams (): Generator
162160 {
163- yield 'by 1 ' => ['chunk ' => 1 ];
164- yield 'by 2 ' => ['chunk ' => 2 ];
165- yield 'by 4 ' => ['chunk ' => 4 ];
166- yield 'by 8 ' => ['chunk ' => 8 ];
167- yield 'by 13 ' => ['chunk ' => 13 ];
168- yield 'by 20 ' => ['chunk ' => 20 ];
169- yield 'by 100 ' => ['chunk ' => 100 ];
161+ yield '100 chunks ' => ['chunkSize ' => 1 ];
162+ yield '25 chunks ' => ['chunkSize ' => 4 ];
163+ yield '10 chunks ' => ['chunkSize ' => 10 ];
170164 }
171165
172166 /**
0 commit comments