3v4l.org

run code in 300+ PHP versions simultaneously
<?hh class Guard { private static bool $guarded = false; public static function acquire(): void { self::$guarded = true; } public static function release(): void { self::$guarded = false; } public static function isGuarded(): bool { return self::$guarded; } } class BatchedWriter { const int BATCH_SIZE = 2; private Set<string> $queue = Set { }; private ?Awaitable<ImmMap<string, string>> $waitHandle = null; public async function write(string $id): Awaitable<string> { $this->queue[] = $id; $all_results = await $this->writeAll(); return $all_results->at($id); } private function writeAll(): Awaitable<ImmMap<string, string>> { $wh = $this->waitHandle; if ($wh === null || HH\Asio\has_finished($wh)) { $wh = $this->writeAllImpl(); $this->waitHandle = $wh; } return $wh; } private async function writeAllImpl(): Awaitable<ImmMap<string, string>> { while (count($this->queue) < self::BATCH_SIZE) { await HH\Asio\later(); } $results = Map { }; foreach ($this->queue as $id) { $results[$id] = $id.' is '.(Guard::isGuarded() ? 'guarded' : 'unguarded'); } $this->queue = Set { }; return $results->immutable(); } <<__Memoize>> public static function get(): BatchedWriter { return new BatchedWriter(); } } function stop_eager_execution(): Awaitable<void> { return RescheduleWaitHandle::create(RescheduleWaitHandle::QUEUE_DEFAULT, 0); } function join_for_guard<T>( (function(): Awaitable<T>) $callback, ): T { $awaitable = async { await stop_eager_execution(); return await $callback(); }; return HH\Asio\join($awaitable); } async function do_unguarded_write(): Awaitable<void> { $result = await BatchedWriter::get()->write(__FUNCTION__); var_dump(__FUNCTION__.': '.$result); } async function do_guarded_write(): Awaitable<void> { $id = __FUNCTION__; await HH\Asio\later(); Guard::acquire(); $result = join_for_guard(async () ==> await BatchedWriter::get()->write($id)); var_dump($id.': '.$result); Guard::release(); } HH\Asio\join(HH\Asio\va( do_unguarded_write(), do_guarded_write(), ));

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.3.40.0130.00318.59
8.3.30.0090.00618.59
8.3.20.0080.00020.26
8.3.10.0070.00021.81
8.3.00.0040.00417.68
8.2.170.0070.00722.96
8.2.160.0070.00721.02
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0040.00420.35
8.2.120.0060.00326.35
8.2.110.0110.00020.94
8.2.100.0000.01117.72
8.2.90.0060.00318.09
8.2.80.0030.00517.97
8.2.70.0040.00417.38
8.2.60.0060.00317.80
8.2.50.0080.00018.10
8.2.40.0040.00422.25
8.2.30.0000.00719.00
8.2.20.0000.00717.82
8.2.10.0050.00318.08
8.2.00.0050.00218.09
8.1.270.0040.00422.03
8.1.260.0070.00026.35
8.1.250.0050.00228.09
8.1.240.0090.00023.92
8.1.230.0080.00420.95
8.1.220.0050.00317.74
8.1.210.0070.00419.80
8.1.200.0060.00317.13
8.1.190.0050.00317.09
8.1.180.0050.00318.10
8.1.170.0030.00518.50
8.1.160.0040.00418.74
8.1.150.0000.00720.05
8.1.140.0000.00719.48
8.1.130.0070.00018.84
8.1.120.0040.00317.32
8.1.110.0000.00817.32
8.1.100.0070.00017.27
8.1.90.0000.00717.38
8.1.80.0000.00717.20
8.1.70.0030.00517.23
8.1.60.0040.00417.45
8.1.50.0030.00917.39
8.1.40.0000.00817.27
8.1.30.0000.00817.44
8.1.20.0040.00417.53
8.1.10.0060.00317.39
8.1.00.0080.00017.39
8.0.300.0070.00019.91
8.0.290.0070.00016.58
8.0.280.0070.00018.24
8.0.270.0000.00716.64
8.0.260.0070.00018.98
8.0.250.0000.00616.73
8.0.240.0040.00416.84
8.0.230.0000.00816.79
8.0.220.0000.00716.64
8.0.210.0040.00416.72
8.0.200.0080.00416.67
8.0.190.0030.00916.86
8.0.180.0040.00416.68
8.0.170.0030.00416.83
8.0.160.0030.00416.64
8.0.150.0000.00816.76
8.0.140.0030.00716.74
8.0.130.0030.00313.26
8.0.120.0050.00316.68
8.0.110.0070.00016.76
8.0.100.0040.00416.53
8.0.90.0030.00316.59
8.0.80.0100.00616.79
8.0.70.0040.00416.62
8.0.60.0000.00716.73
8.0.50.0040.00416.79
8.0.30.0100.00917.03
8.0.20.0120.00617.40
8.0.10.0000.00716.75
8.0.00.0080.00816.57
7.4.330.0060.00015.55
7.4.320.0030.00316.51
7.4.300.0030.00316.25
7.4.290.0030.00316.38
7.4.280.0000.00716.30
7.4.270.0030.00316.35
7.4.260.0000.00716.45
7.4.250.0030.00316.38
7.4.240.0040.00416.42
7.4.230.0050.00216.41
7.4.220.0090.01216.48
7.4.210.0090.00716.45
7.4.200.0030.00616.55
7.4.160.0060.01016.41
7.4.150.0100.01017.40
7.4.140.0130.00717.86
7.4.130.0110.00816.30
7.4.120.0120.01016.38
7.4.110.0070.01016.40
7.4.100.0030.01416.28
7.4.90.0150.00316.23
7.4.80.0160.00619.39
7.4.70.0100.01316.35
7.4.60.0120.00316.50
7.4.50.0120.00416.18
7.4.40.0000.01516.46
7.4.30.0060.00916.32
7.3.330.0000.00513.20
7.3.320.0000.00513.08
7.3.310.0040.00416.13
7.3.300.0030.00316.13
7.3.290.0050.00215.96
7.3.280.0080.01116.11
7.3.270.0090.00917.40
7.3.260.0120.00916.26
7.3.250.0110.00816.13
7.3.240.0100.00916.34
7.3.230.0070.01016.22
7.3.210.0090.00716.38
7.3.200.0080.00916.48
7.3.190.0100.01016.13
7.3.180.0110.00416.39
7.3.170.0070.00916.23
7.3.160.0080.00816.06
7.2.330.0070.01416.27
7.2.320.0090.00916.50
7.2.310.0060.01016.29
7.2.300.0170.00316.43
7.2.290.0100.00616.29
7.1.40.0400.00732.43
7.1.30.0300.02032.40
7.1.20.0330.02032.54
7.1.10.0370.01714.56
7.1.00.0230.01314.50
7.0.180.0670.01014.15
7.0.170.0200.01714.06
7.0.160.0270.01014.04
7.0.150.0330.01014.26
7.0.140.0330.01314.37
7.0.130.0330.00714.40
7.0.120.0300.01014.45
7.0.110.0370.01014.39
7.0.100.0270.01014.40
7.0.90.0200.01314.25
7.0.80.0300.00314.31
7.0.70.0230.01014.14
7.0.60.0270.00313.84
7.0.50.0200.01014.21
7.0.40.0370.01314.41
7.0.30.0300.01714.34
7.0.20.0230.01014.52
7.0.10.0300.00314.15
7.0.00.0300.00314.50

preferences:
46.9 ms | 400 KiB | 5 Q