3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Water { public $color = 'clear'; public $temp = 'cold'; } class Pipeline { /** * @var array The parameters to pass through */ protected $parameters = []; /** * @var \Closure[] The list of pipes that the parameters will fall through * Pipe should match function($parameter..., \Closure $next) {} */ protected $pipes = []; /** * @type \Closure The "then" closure, it will receive the parameters you pipe through */ protected $thenClosure; /** * @inheritdoc */ public function send(...$parameters) : PipelineMap { $this->parameters = $parameters; return $this; } /** * @inheritdoc */ public function through($pipes) : PipelineMap { $this->pipes = is_array($pipes) ? $pipes : func_get_args(); return $this; } /** * @inheritdoc */ public function then(callable $then) : PipelineMap { $this->thenClosure = $then; return $this; } /** * @inheritdoc */ public function execute() { $pipes = array_reverse($this->pipes); /** @type \Closure $linked_closure */ $linked_closure = array_reduce($pipes, $this->getIterator(), $this->getInitial($this->thenClosure)); return $linked_closure(...$this->parameters); } /** * Get the iterator closure, this wraps every item in the list and injects the * @return \Closure */ protected function getIterator() : \Closure { return function ($next, $pipe) { return function (...$parameters) use ($next, $pipe) { $parameters[] = $next; return $pipe(...$parameters); }; }; } /** * The initial closure * @return \Closure */ protected function getInitial(\Closure $then) : \Closure { return function(...$parameters) use ($then) { return $then(...$parameters); }; } } <?php $color_water_blue_pipe = function (Water $water, callable $next_pipe) { $water->color = 'blue'; // We colored it, now we're done. Send it to the next pipe and return the result! return $next_pipe($water); }; $heat_water_pipe = function (Water $water, $callable $next_pipe) { $water->temp = 'hot'; }; // Make some water $water = $factory->getWater(); // Send it through our pipes $piped_water = (new \Buttress\Pipeline\Pipeline()) ->send($water) ->through([ $color_water_blue_pipe, $heat_water_pipe ]) ->then(function($water) { return $water; }); echo "The water is {$piped_water->color} and {$piped_water->temp}!";

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.20.0230.06720.12
7.0.10.0070.06320.22
7.0.00.0100.05320.06
5.6.170.0230.04020.53
5.6.160.0130.06320.39
5.6.150.0100.07718.18
5.6.140.0070.05018.28
5.6.130.0030.04018.18
5.6.120.0170.07320.98
5.6.110.0100.08021.04
5.6.100.0070.07721.01
5.6.90.0030.06321.02
5.6.80.0130.07720.49
5.5.310.0370.05320.36
5.5.300.0070.04017.99
5.5.290.0000.06018.05
5.5.280.0000.06020.85
5.5.270.0070.05020.76
5.5.260.0000.05020.86
5.5.250.0130.03720.55
5.5.240.0230.04020.27

preferences:
148.35 ms | 1398 KiB | 7 Q