|
12 | 12 |
|
13 | 13 | use Clue\React\Csv\AssocDecoder; |
14 | 14 | use React\ChildProcess\Process; |
15 | | -use React\EventLoop\Factory; |
| 15 | +use React\EventLoop\Loop; |
16 | 16 |
|
17 | 17 | require __DIR__ . '/../vendor/autoload.php'; |
18 | 18 |
|
19 | 19 | if (extension_loaded('xdebug')) { |
20 | 20 | echo 'NOTICE: The "xdebug" extension is loaded, this has a major impact on performance.' . PHP_EOL; |
21 | 21 | } |
22 | 22 |
|
23 | | -$loop = Factory::create(); |
24 | | - |
25 | 23 | // This benchmark example spawns the decompressor in a child `gunzip` process |
26 | 24 | // because parsing CSV files is already mostly CPU-bound and multi-processing |
27 | 25 | // is preferred here. If the input source is slower (such as an HTTP download) |
|
32 | 30 | 1 => array('pipe', 'w'), |
33 | 31 | STDERR |
34 | 32 | )); |
35 | | -$process->start($loop); |
| 33 | +$process->start(); |
36 | 34 | $decoder = new AssocDecoder($process->stdout); |
37 | 35 |
|
38 | 36 | $count = 0; |
|
41 | 39 | }); |
42 | 40 |
|
43 | 41 | $start = microtime(true); |
44 | | -$report = $loop->addPeriodicTimer(0.05, function () use (&$count, $start) { |
| 42 | +$report = Loop::addPeriodicTimer(0.05, function () use (&$count, $start) { |
45 | 43 | printf("\r%d records in %0.3fs...", $count, microtime(true) - $start); |
46 | 44 | }); |
47 | 45 |
|
48 | | -$decoder->on('close', function () use (&$count, $report, $loop, $start) { |
| 46 | +$decoder->on('close', function () use (&$count, $report, $start) { |
49 | 47 | $now = microtime(true); |
50 | | - $loop->cancelTimer($report); |
| 48 | + Loop::cancelTimer($report); |
51 | 49 |
|
52 | 50 | printf("\r%d records in %0.3fs => %d records/s\n", $count, $now - $start, $count / ($now - $start)); |
53 | 51 | }); |
54 | | - |
55 | | -$loop->run(); |
0 commit comments