|
15 | 15 | // $ php examples/91-benchmark-count.php < title.ratings.ndjson |
16 | 16 |
|
17 | 17 | use Clue\React\NDJson\Decoder; |
18 | | -use React\EventLoop\Factory; |
| 18 | +use React\EventLoop\Loop; |
19 | 19 | use React\Stream\ReadableResourceStream; |
20 | 20 |
|
21 | 21 | require __DIR__ . '/../vendor/autoload.php'; |
|
24 | 24 | echo 'NOTICE: The "xdebug" extension is loaded, this has a major impact on performance.' . PHP_EOL; |
25 | 25 | } |
26 | 26 |
|
27 | | -$loop = Factory::create(); |
28 | | -$decoder = new Decoder(new ReadableResourceStream(STDIN, $loop), true); |
| 27 | +$decoder = new Decoder(new ReadableResourceStream(STDIN), true); |
29 | 28 |
|
30 | 29 | $count = 0; |
31 | 30 | $decoder->on('data', function () use (&$count) { |
32 | 31 | ++$count; |
33 | 32 | }); |
34 | 33 |
|
35 | 34 | $start = microtime(true); |
36 | | -$report = $loop->addPeriodicTimer(0.05, function () use (&$count, $start) { |
| 35 | +$report = Loop::addPeriodicTimer(0.05, function () use (&$count, $start) { |
37 | 36 | printf("\r%d records in %0.3fs...", $count, microtime(true) - $start); |
38 | 37 | }); |
39 | 38 |
|
40 | | -$decoder->on('close', function () use (&$count, $report, $loop, $start) { |
| 39 | +$decoder->on('close', function () use (&$count, $report, $start) { |
41 | 40 | $now = microtime(true); |
42 | | - $loop->cancelTimer($report); |
| 41 | + Loop::cancelTimer($report); |
43 | 42 |
|
44 | 43 | printf("\r%d records in %0.3fs => %d records/s\n", $count, $now - $start, $count / ($now - $start)); |
45 | 44 | }); |
46 | | - |
47 | | -$loop->run(); |
0 commit comments