3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Acme { class Collection { private $_items; public function __construct(array $items = [])/*: void*/ { $this->_items = $items; } public function filter(callable $callback): self { foreach ($this->_items as $key => $value) { if (!call_user_func($callback, $value)) { unset($this->_items[$key]); } } return $this; } public function map(callable $callback): self { foreach ($this->_items as $key => $value) { $this->_items[$key] = call_user_func($callback, $key, $value); } return $this; } public function reindex(): self { $this->_items = array_values($this->_items); } public function sprintf(string $format): self { return $this->map(function ($key, $value) use ($format) { return substr_count($format, '%s') === 1 ? sprintf($format, $value) : sprintf($format, $key, $value); }); } public function implode(string $delimiter = ''): string { $output = ''; $first = TRUE; foreach ($this->_items as $value) { if ($first) { $output .= $value; $first = FALSE; } else { $output .= "$delimiter$value"; } } return $output; } public static function property(string $property): callable { return function ($key, $value) use ($name) { return $value->$property; }; } } } namespace { use Acme\Collection; echo (new Collection([ 'one', 'two', (object)['foo' => 'FOO', 'bar' => 'BAR', 'baz' => 'BAZ'], 'three', (object)['bar' => 'BAR', 'qux' => 'QUX'], ])) ->filter('is_object') ->map(Collection::property('bar')) ->reindex() ->sprintf('(%s,%s)') ->implode('_');

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)
7.0.10.0070.04320.16
7.0.00.0030.04320.10
5.6.160.0100.05320.54
5.6.150.0070.07318.14
5.6.140.0100.08018.12
5.6.130.0000.04318.14
5.6.120.0170.07321.13
5.6.110.0030.04321.00
5.6.100.0170.07721.00
5.6.90.0030.08021.08
5.6.80.0100.03720.37
5.5.300.0030.08317.98
5.5.290.0000.09717.96
5.5.280.0030.06020.78
5.5.270.0170.07720.73
5.5.260.0170.07320.68
5.5.250.0100.03320.67
5.5.240.0130.07020.20

preferences:
146.6 ms | 939 KiB | 8 Q