3v4l.org

run code in 300+ PHP versions simultaneously
<?php class FiberPool { /** @var Fiber[] */ private array $fibers = []; private int $max = 10; private array $results = []; public function __construct( private \Generator $generator, ) { } public function wait(): void { while ($this->fibers || $this->generator->valid()) { // Fill up the pending fibers while (count($this->fibers) < $this->max && $this->generator->valid()) { $this->startNextItem(); } foreach ($this->fibers as $key => $fiber) { // TBD: We could try/catch this and set the exception to the results array. if ($fiber->isSuspended()) { $fiber->resume(); } else if (!$fiber->isStarted()) { $fiber->start(); } if ($fiber->isTerminated()) { $this->results[$key] = $fiber->getReturn(); unset($this->fibers[$key]); $this->startNextItem(); } } // If we're in a fiber loop ourselves then suspend up the chain once per loop. if (Fiber::getCurrent()) { Fiber::suspend(); } } } public function getResults(): array { return $this->results; } private function startNextItem(): void { if ($this->generator->valid()) { $callable = $this->generator->current(); $this->fibers[$this->generator->key()] = new Fiber($callable); $this->generator->next(); } } } $consistentSuspend = function () { static $seed = [0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0]; return array_pop($seed); }; $example = new FiberPool((function () use ($consistentSuspend) { $output = array_combine(range('A', 'Z'), range(1,26)); foreach ($output as $key => $item) { echo 'generating ', $item, "\n"; yield $key => function () use ($consistentSuspend, $item) { echo 'starting ', $item, "\n"; while ($consistentSuspend()) { echo 'suspending ', $item, "\n"; Fiber::suspend(); } echo 'returning ', $item, "\n"; return $item; }; } })()); $example->wait(); print_r($example->getResults());

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.120.0050.00620.48
8.4.110.0150.00822.47
8.4.100.0100.00918.00
8.4.90.0120.01017.93
8.4.80.0130.00917.80
8.4.70.0080.00517.80
8.4.60.0060.00420.58
8.4.50.0170.00617.90
8.4.40.0180.00418.83
8.4.30.0070.01720.64
8.4.20.0100.01320.71
8.4.10.0030.00619.75
8.3.250.0140.00718.73
8.3.240.0120.00716.79
8.3.230.0120.00816.88
8.3.220.0160.00516.94
8.3.210.0100.01017.04
8.3.200.0060.00416.79
8.3.190.0120.00718.99
8.3.180.0110.00916.89
8.3.170.0060.01320.61
8.3.160.0130.00717.28
8.3.150.0040.00417.36
8.3.140.0170.00318.66
8.3.130.0030.00718.37
8.3.120.0070.01420.83
8.3.110.0140.00720.94
8.3.100.0060.00318.29
8.3.90.0100.00726.77
8.3.80.0030.00717.97
8.3.70.0200.00318.43
8.3.60.0140.01125.92
8.3.50.0120.01225.92
8.3.40.0500.00025.92
8.3.30.0360.01425.92
8.3.20.0380.00825.92
8.3.10.0340.00825.92
8.3.00.0520.00025.92
8.2.290.0130.00720.32
8.2.280.0060.00322.25
8.2.270.0120.00917.13
8.2.260.0030.01616.65
8.2.250.0080.00018.72
8.2.240.0040.00717.41
8.2.230.0020.00522.58
8.2.220.0230.00024.06
8.2.210.0140.00726.77
8.2.200.0100.00016.63
8.2.190.0100.00716.75
8.2.180.0310.00925.92
8.2.170.0320.00625.92
8.2.160.0360.01025.92
8.2.150.0450.00725.92
8.2.140.0590.00425.92
8.2.130.0330.01525.92
8.2.120.0330.01325.92
8.2.110.0430.00325.92
8.2.100.0370.01125.92
8.2.90.0400.01125.92
8.2.80.0400.01225.92
8.2.70.0410.00325.92
8.2.60.0290.02125.92
8.2.50.0360.01325.92
8.2.40.0290.01825.92
8.2.30.0280.01225.92
8.2.20.0390.00725.92
8.2.10.0360.00625.92
8.2.00.0430.00425.92
8.1.330.0080.00218.54
8.1.320.0130.00816.27
8.1.310.0000.00916.64
8.1.300.0100.01020.07
8.1.290.0100.00030.84
8.1.280.0450.00725.92
8.1.270.0480.00325.92
8.1.260.0370.00925.92
8.1.250.0410.00925.92
8.1.240.0350.01025.92
8.1.230.0290.01525.92
8.1.220.0330.01225.92
8.1.210.0370.01725.92
8.1.200.0310.01125.92
8.1.190.0450.00625.92
8.1.180.0550.00825.92
8.1.170.0440.00425.92
8.1.160.0350.01225.92
8.1.150.0420.00325.92
8.1.140.0310.01525.92
8.1.130.0300.01525.92
8.1.120.0360.01125.92
8.1.110.0350.01025.92
8.1.100.0350.01025.92
8.1.90.0320.01325.92
8.1.80.0280.01225.92
8.1.70.0320.00925.92
8.1.60.0290.01625.92
8.1.50.0390.01025.92
8.1.40.0400.00925.92
8.1.30.0330.01125.92
8.1.20.0380.01025.92
8.1.10.0470.01325.92
8.1.00.0310.00925.92

preferences:
25.84 ms | 403 KiB | 5 Q