3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Implements a read/write buffer. */ class Buffer { protected $eof = false; protected $indexRead = 0; protected $indexWrite = 0; protected $buffer = []; public function write($bytes) { if ($bytes === null) { $this->eof = true; } else { $this->buffer[$this->indexWrite++] = $bytes; } } public function read($length = 4096) { if (!$this->buffer) { return $this->eof ? null : ''; } $output = ''; $outputLength = 0; while ($this->indexRead < $this->indexWrite) { $chunk = $this->buffer[$this->indexRead]; $chunkLength = \strlen($chunk); if ($outputLength + $chunkLength == $length) { unset($this->buffer[$this->indexRead++]); $output .= $chunk; return $output; } if ($outputLength + $chunkLength > $length) { $slice = $length - $outputLength; $this->buffer[$this->indexRead] = \substr($chunk, $slice); $output .= \substr($chunk, 0, $slice); return $output; } unset($this->buffer[$this->indexRead++]); $output .= $chunk; $outputLength += $chunkLength; } return $output; } } $b = new Buffer(); $b->write('ABCDEFGHIJ'); $b->write('KLMNOPQRSTUVWXYZ'); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); echo 'Writing more...' . PHP_EOL; $b->write('01234567890'); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3)); echo 'EOF...' . PHP_EOL; $b->write(null); var_dump($b->read(3)); var_dump($b->read(3)); var_dump($b->read(3));

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.60.0160.00018.56
8.3.50.0140.00318.30
8.3.40.0040.01118.72
8.3.30.0070.00718.67
8.3.20.0050.00220.34
8.3.10.0050.00320.91
8.3.00.0080.00020.77
8.2.180.0120.00918.39
8.2.170.0190.00022.96
8.2.160.0070.00720.53
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0030.00521.06
8.2.120.0000.00726.35
8.2.110.0100.00020.96
8.2.100.0080.00317.95
8.2.90.0050.00319.35
8.2.80.0090.00017.97
8.2.70.0000.00917.63
8.2.60.0030.00517.93
8.2.50.0050.00318.10
8.2.40.0030.00622.36
8.2.30.0000.00819.31
8.2.20.0000.00718.20
8.2.10.0000.00818.21
8.2.00.0020.00518.13
8.1.280.0040.01525.92
8.1.270.0040.00422.36
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0090.00022.66
8.1.230.0080.00419.34
8.1.220.0030.00617.91
8.1.210.0030.00518.77
8.1.200.0030.00617.48
8.1.190.0050.00317.36
8.1.180.0000.00818.10
8.1.170.0000.00818.62
8.1.160.0000.00819.00
8.1.150.0030.00519.02
8.1.140.0020.00519.60
8.1.130.0000.00720.61
8.1.120.0050.00317.50
8.1.110.0030.00617.59
8.1.100.0000.00917.52
8.1.90.0040.00417.57
8.1.80.0040.00417.56
8.1.70.0000.00717.49
8.1.60.0000.00917.52
8.1.50.0040.00417.54
8.1.40.0060.00617.49
8.1.30.0040.00417.62
8.1.20.0000.00817.63
8.1.10.0040.00417.61
8.1.00.0000.00717.44
8.0.300.0040.00418.77
8.0.290.0000.00816.88
8.0.280.0030.00318.56
8.0.270.0040.00417.26
8.0.260.0000.00619.00
8.0.250.0000.00716.90
8.0.240.0000.00717.01
8.0.230.0030.00317.04
8.0.220.0040.00416.92
8.0.210.0000.00716.98
8.0.200.0000.00716.91
8.0.190.0030.00617.02
8.0.180.0050.00217.00
8.0.170.0040.00416.90
8.0.160.0070.00016.89
8.0.150.0030.00516.80
8.0.140.0030.00616.85
8.0.130.0030.00313.34
8.0.120.0030.00616.98
8.0.110.0020.00516.95
8.0.100.0000.00717.00
8.0.90.0070.00016.79
8.0.80.0090.01217.03
8.0.70.0050.00216.81
8.0.60.0000.00816.87
8.0.50.0050.00216.81
8.0.30.0050.01217.22
8.0.20.0100.01217.40
8.0.10.0000.00816.96
8.0.00.0130.01016.77
7.4.330.0000.00615.55
7.4.320.0000.00616.73
7.4.300.0060.00016.59
7.4.290.0030.00816.72
7.4.280.0070.00016.56
7.4.270.0040.00416.69
7.4.260.0000.00716.46
7.4.250.0030.00516.53
7.4.240.0040.00416.64
7.4.230.0000.00716.49
7.4.220.0160.01016.64
7.4.210.0060.00916.61
7.4.200.0000.00716.38
7.4.160.0080.01016.57
7.4.150.0110.00717.40
7.4.140.0110.00717.86
7.4.130.0130.00716.70
7.4.120.0060.01216.66
7.4.110.0130.00616.69
7.4.100.0100.01016.38
7.4.90.0110.00716.52
7.4.80.0070.01219.39
7.4.70.0040.01516.40
7.4.60.0100.00716.53
7.4.50.0070.00716.38
7.4.40.0070.01316.50
7.4.30.0140.00316.73
7.4.00.0070.00715.22
7.3.330.0030.00213.26
7.3.320.0060.00013.42
7.3.310.0070.00016.41
7.3.300.0040.00416.31
7.3.290.0100.00816.48
7.3.280.0090.00716.39
7.3.270.0080.01217.40
7.3.260.0100.00716.47
7.3.250.0100.00916.47
7.3.240.0110.00716.59
7.3.230.0090.00916.41
7.3.210.0060.01016.42
7.3.200.0080.00816.54
7.3.190.0100.00616.75
7.3.180.0090.00816.51
7.3.170.0030.01316.66
7.3.160.0150.00316.36
7.2.330.0080.01216.91
7.2.320.0080.00816.61
7.2.310.0120.00616.84
7.2.300.0060.01116.57
7.2.290.0080.01016.88
7.2.60.0070.00717.01
7.1.200.0110.00015.84
7.1.80.0090.01018.22
7.1.70.0030.01217.24
7.1.60.0240.01434.80
7.1.50.0250.01334.55
7.1.40.0160.01534.33
7.1.30.0210.01334.51
7.1.20.0220.01534.58
7.1.10.0060.01016.81
7.1.00.0110.00716.57
7.0.200.0000.01616.92
7.0.190.0080.01016.82
7.0.180.0090.00916.31
7.0.170.0140.00416.24
7.0.160.0060.01016.06
7.0.150.0030.01616.18
7.0.140.0070.00716.49
7.0.130.0060.01216.67
7.0.120.0060.01316.42
7.0.110.0030.01416.54
7.0.100.0030.01416.23
7.0.90.0030.01316.26
7.0.80.0050.00816.52
7.0.70.0090.00516.23
7.0.60.0060.00616.07
7.0.50.0030.01416.36
7.0.40.0080.00816.64
7.0.30.0100.00516.38
7.0.20.0030.01216.38
7.0.10.0080.00616.38
7.0.00.0030.01016.33

preferences:
56.05 ms | 400 KiB | 5 Q