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, \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)
5.6.160.0100.08320.54
5.6.150.0030.07718.29
5.6.140.0070.07318.29
5.6.130.0130.07318.13
5.6.120.0070.04021.00
5.6.110.0000.07321.11
5.6.100.0070.03721.00
5.6.90.0100.08021.02
5.6.80.0030.03720.41
5.5.300.0030.07717.95
5.5.290.0100.08317.97
5.5.280.0030.05320.83
5.5.270.0130.07320.88
5.5.260.0030.08320.69
5.5.250.0070.09020.59
5.5.240.0200.07720.25

preferences:
151.46 ms | 1394 KiB | 7 Q