3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StringStreamWrapper { const PROTOCOL = "stringstream"; private $stringstream; private $position; private $stringlength; public function stream_open($path, $mode, $options, &$opened_path) { $contextOptions = stream_context_get_options($this->context); if (!isset($contextOptions[self::PROTOCOL]['string'])) return false; $this->position = 0; // this is our stream! $this->stringstream = $contextOptions[self::PROTOCOL]['string']; $this->stringlength = strlen($this->stringstream); return true; } public function stream_read($len) { $data = substr($this->stringstream, $this->position, $len); $this->position += strlen($data); return $data; } public function stream_write($data){ $l = strlen($data); $this->stringstream = substr($this->stringstream, 0, $this->position) . $data . substr($this->stringstream, $this->position += $l); $this->stringlength = strlen($this->stringstream); return $l; } public function stream_seek($offset, $whence = SEEK_SET) { if ($whence == SEEK_CUR) { $this->position += $offset; } else if ($whence == SEEK_END) { $this->position = $this->stringlength + $offset; } else { $this->position = $offset; } return true; } public function stream_tell() { return $this->position; } public function stream_eof() { return ($this->position >= $this->stringlength); } public function stream_stat() { return array( 7 => $this->stringlength, 'size' => $this->stringlength, ); } static public function Open($string) { $context = stream_context_create(array(self::PROTOCOL => array('string' => &$string))); return fopen(self::PROTOCOL . "://",'r', false, $context); } } stream_wrapper_register(StringStreamWrapper::PROTOCOL, "StringStreamWrapper"); ####################################### $testString = 'test'; echo "base64_encode = " . base64_encode($testString).PHP_EOL; ####################################### # put data in the StringStreamWrapper $stringstream = StringStreamWrapper::Open($testString); # get the output stream (as z-push does) $output = fopen("php://output", "w+"); # attach write filter to output $filter = stream_filter_append($output, 'convert.base64-encode'); echo "outputstream = "; # write to output $bytes = stream_copy_to_stream($stringstream, $output); write($output, chr(0)); echo "\n wrote $bytes";

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.0040.01118.43
8.3.50.0110.00418.18
8.3.40.0070.00718.90
8.3.30.0110.00418.79
8.3.20.0050.00320.46
8.3.10.0050.00323.68
8.3.00.0050.00220.09
8.2.180.0140.00716.88
8.2.170.0070.00722.96
8.2.160.0100.00320.16
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0040.00419.30
8.2.120.0030.00626.35
8.2.110.0060.00320.52
8.2.100.0040.00818.05
8.2.90.0050.00319.41
8.2.80.0000.00817.97
8.2.70.0100.00017.61
8.2.60.0140.00517.43
8.2.50.0000.00818.07
8.2.40.0050.00321.13
8.2.30.0070.00020.73
8.2.20.0000.00917.92
8.2.10.0060.00318.16
8.2.00.0040.00418.07
8.1.280.0070.01125.92
8.1.270.0040.00420.25
8.1.260.0000.00728.09
8.1.250.0040.00428.09
8.1.240.0080.00022.06
8.1.230.0060.00617.89
8.1.220.0040.00417.77
8.1.210.0040.00418.77
8.1.200.0090.00017.35
8.1.190.0030.00617.35
8.1.180.0030.00618.10
8.1.170.0030.00618.53
8.1.160.0040.00420.89
8.1.150.0040.00418.94
8.1.140.0080.00019.50
8.1.130.0040.00417.75
8.1.120.0000.00717.51
8.1.110.0050.00217.50
8.1.100.0080.00017.39
8.1.90.0000.00717.39
8.1.80.0060.00317.50
8.1.70.0040.00417.41
8.1.60.0050.00317.64
8.1.50.0030.00617.56
8.1.40.0050.00317.50
8.1.30.0000.00817.68
8.1.20.0000.00817.74
8.1.10.0000.00717.67
8.1.00.0080.00017.52
8.0.300.0000.00718.77
8.0.290.0000.00717.00
8.0.280.0000.00818.56
8.0.270.0030.00317.40
8.0.260.0000.00617.31
8.0.250.0000.00817.13
8.0.240.0030.00517.01
8.0.230.0030.00317.13
8.0.220.0040.00417.08
8.0.210.0000.00716.97
8.0.200.0030.00317.14
8.0.190.0040.00417.09
8.0.180.0040.00417.09
8.0.170.0080.00017.02
8.0.160.0070.00017.09
8.0.150.0100.00016.96
8.0.140.0000.00717.03
8.0.130.0060.00013.54
8.0.120.0050.00417.07
8.0.110.0040.00417.04
8.0.100.0040.00416.93
8.0.90.0000.00717.13
8.0.80.0060.00917.10
8.0.70.0000.00816.92
8.0.60.0040.00417.04
8.0.50.0050.00217.05
8.0.30.0050.01317.17
8.0.20.0090.01017.40
8.0.10.0050.00316.91
8.0.00.0090.01216.96
7.4.330.0000.00516.73
7.4.320.0000.00716.58
7.4.300.0000.00616.56
7.4.290.0070.00016.50
7.4.280.0080.00516.59
7.4.270.0030.00616.46
7.4.260.0040.00716.65
7.4.250.0000.00816.47
7.4.240.0040.00316.57
7.4.230.0000.00716.68
7.4.220.0170.01016.61
7.4.210.0110.00816.61
7.4.200.0000.00716.72
7.4.160.0070.00716.53
7.4.150.0060.01317.40
7.4.140.0080.01317.86
7.4.130.0130.00516.51
7.4.120.0050.01316.60
7.4.110.0030.01816.52
7.4.100.0130.00416.56
7.4.90.0100.00716.53
7.4.80.0060.01219.39
7.4.70.0070.01016.74
7.4.60.0120.01216.63
7.4.50.0110.00516.70
7.4.40.0030.01416.46
7.4.30.0110.00716.62
7.4.00.0000.01315.05
7.3.330.0030.00313.56
7.3.320.0000.00513.55
7.3.310.0000.00716.39
7.3.300.0040.00416.55
7.3.290.0120.00416.56
7.3.280.0080.01016.52
7.3.270.0080.00817.40
7.3.260.0180.00416.39
7.3.250.0090.00916.59
7.3.240.0080.01216.53
7.3.230.0090.00916.49
7.3.210.0040.01416.54
7.3.200.0060.01116.44
7.3.190.0100.00716.64
7.3.180.0070.01016.56
7.3.170.0070.01416.50
7.3.160.0130.00316.63
7.2.330.0070.01416.89
7.2.320.0060.01216.61
7.2.310.0070.01016.74
7.2.300.0090.00916.63
7.2.290.0080.01016.90
7.2.60.0070.00716.85
7.2.00.0090.00619.59
7.1.200.0210.00715.46
7.1.100.0030.01018.25
7.1.70.0030.00517.23
7.1.60.0030.02219.13
7.1.50.0000.02216.97
7.1.00.0030.07022.35
7.0.200.0050.00316.74
7.0.60.0070.03719.95
7.0.50.0070.07717.93
7.0.40.0100.05720.21
7.0.30.0330.04720.09
7.0.20.0270.05320.23
7.0.10.0030.04720.15
7.0.00.0030.04320.23
5.6.280.0030.03021.13
5.6.210.0100.07020.78
5.6.200.0000.04318.29
5.6.190.0030.08720.50
5.6.180.0300.02720.67
5.6.170.0300.07720.53
5.6.160.0100.05320.44
5.6.150.0170.06018.16
5.6.140.0000.04318.27
5.6.130.0170.06718.14
5.6.120.0030.07721.01
5.6.110.0100.08320.91
5.6.100.0070.04021.02
5.6.90.0100.08021.09
5.6.80.0100.03720.41
5.5.350.0200.06720.51
5.5.340.0030.04718.09
5.5.330.0200.05720.26
5.5.320.0400.05320.35
5.5.310.0200.05720.39
5.5.300.0030.04018.04
5.5.290.0070.04717.95
5.5.280.0070.05020.82
5.5.270.0070.08320.88
5.5.260.0030.06720.91
5.5.250.0030.08320.60
5.5.240.0270.07020.27

preferences:
40.33 ms | 400 KiB | 5 Q