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)); var_dump('Writing more...'); $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)); var_dump('EOF...'); $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.0100.01018.43
8.3.50.0060.00918.19
8.3.40.0120.00619.02
8.3.30.0070.00718.76
8.3.20.0040.00420.28
8.3.10.0080.00021.04
8.3.00.0050.00320.89
8.2.180.0110.00716.50
8.2.170.0100.01022.96
8.2.160.0070.00719.04
8.2.150.0150.00024.18
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0040.00421.04
8.2.110.0040.00722.25
8.2.100.0080.00317.91
8.2.90.0080.00017.88
8.2.80.0040.00417.97
8.2.70.0030.00517.63
8.2.60.0030.00617.75
8.2.50.0040.00418.04
8.2.40.0080.00018.34
8.2.30.0000.00718.07
8.2.20.0000.00718.20
8.2.10.0000.00818.07
8.2.00.0000.00818.30
8.1.280.0060.01225.92
8.1.270.0080.00024.66
8.1.260.0160.00326.35
8.1.250.0090.00628.09
8.1.240.0000.01020.94
8.1.230.0000.01217.73
8.1.220.0090.00017.79
8.1.210.0000.00818.77
8.1.200.0030.00717.47
8.1.190.0040.00417.47
8.1.180.0030.00718.10
8.1.170.0080.00018.84
8.1.160.0040.00418.96
8.1.150.0000.00819.01
8.1.140.0000.00719.64
8.1.130.0080.00017.59
8.1.120.0070.00017.58
8.1.110.0050.00217.44
8.1.100.0050.00317.55
8.1.90.0040.00417.58
8.1.80.0000.00717.38
8.1.70.0040.00417.42
8.1.60.0040.00417.57
8.1.50.0030.00517.60
8.1.40.0070.00017.49
8.1.30.0040.00417.66
8.1.20.0030.00517.64
8.1.10.0000.00717.68
8.1.00.0040.00417.56
8.0.300.0040.00418.77
8.0.290.0030.00616.88
8.0.280.0040.00418.54
8.0.270.0040.00417.38
8.0.260.0000.00716.77
8.0.250.0070.00016.89
8.0.240.0050.00317.10
8.0.230.0000.00716.96
8.0.220.0030.00316.88
8.0.210.0070.00017.03
8.0.200.0060.00016.91
8.0.190.0050.00316.93
8.0.180.0040.00417.03
8.0.170.0070.00016.91
8.0.160.0000.00817.00
8.0.150.0040.00417.01
8.0.140.0000.00816.93
8.0.130.0000.00513.43
8.0.120.0040.00416.93
8.0.110.0070.00016.80
8.0.100.0080.00016.90
8.0.90.0040.00417.02
8.0.80.0120.00616.91
8.0.70.0070.00016.85
8.0.60.0040.00416.79
8.0.50.0040.00416.95
8.0.30.0080.01017.09
8.0.20.0120.00917.40
8.0.10.0040.00417.20
8.0.00.0100.01317.15
7.4.330.0040.00015.55
7.4.320.0070.00016.71
7.4.300.0000.00616.48
7.4.290.0040.00416.67
7.4.280.0030.00516.49
7.4.270.0070.00016.70
7.4.260.0050.00216.65
7.4.250.0050.00216.64
7.4.240.0000.00716.59
7.4.230.0000.00716.57
7.4.220.0120.01516.70
7.4.210.0100.00616.62
7.4.200.0030.00616.70
7.4.160.0130.00516.56
7.4.150.0140.00817.40
7.4.140.0090.01117.86
7.4.130.0080.01016.56
7.4.120.0090.01016.63
7.4.110.0100.01016.52
7.4.100.0110.00716.58
7.4.90.0040.01216.51
7.4.80.0040.01319.39
7.4.70.0060.01216.71
7.4.60.0130.00616.63
7.4.50.0000.01416.43
7.4.40.0110.00716.67
7.4.30.0040.01216.49
7.4.00.0090.00915.08
7.3.330.0000.00613.47
7.3.320.0050.00013.26
7.3.310.0030.00316.42
7.3.300.0070.00016.28
7.3.290.0120.00716.44
7.3.280.0070.01016.44
7.3.270.0100.01017.40
7.3.260.0120.00816.51
7.3.250.0130.00716.46
7.3.240.0090.01116.55
7.3.230.0130.00316.38
7.3.210.0060.01216.39
7.3.200.0060.01516.50
7.3.190.0070.01616.69
7.3.180.0120.00616.43
7.3.170.0130.01016.76
7.3.160.0060.01016.51
7.2.330.0110.00616.75
7.2.320.0130.01116.89
7.2.310.0030.01816.92
7.2.300.0140.00316.56
7.2.290.0100.00716.90
7.2.60.0060.00317.16
7.1.200.0000.01115.91
7.1.80.0130.00718.11
7.1.70.0090.01117.19
7.1.60.0290.01035.24
7.1.50.0210.01634.56
7.1.40.0230.00834.52
7.1.30.0120.02134.54
7.1.20.0160.01834.34
7.1.10.0060.01116.64
7.1.00.0030.01516.77
7.0.200.0060.01116.73
7.0.190.0030.01416.83
7.0.180.0040.01216.21
7.0.170.0000.01716.18
7.0.160.0050.01116.37
7.0.150.0060.01416.20
7.0.140.0060.00916.41
7.0.130.0030.01416.80
7.0.120.0070.01116.71
7.0.110.0080.01116.56
7.0.100.0120.00616.59
7.0.90.0120.00716.29
7.0.80.0050.01416.38
7.0.70.0160.00916.34
7.0.60.0030.01616.14
7.0.50.0100.00416.44
7.0.40.0030.01216.29
7.0.30.0080.00916.59
7.0.20.0050.01016.47
7.0.10.0020.01416.63
7.0.00.0050.01116.59

preferences:
59.14 ms | 400 KiB | 5 Q