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); }; } } // Lets make some pipes $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.0300.07720.23
7.0.10.0070.06020.15
7.0.00.0030.09020.16
5.6.170.0200.04020.42
5.6.160.0070.08720.44
5.6.150.0130.07318.25
5.6.140.0100.05718.17
5.6.130.0070.07718.27
5.6.120.0130.08021.14
5.6.110.0170.07021.11
5.6.100.0200.05721.04
5.6.90.0030.07020.96
5.6.80.0100.07720.41
5.5.310.0430.06720.36
5.5.300.0030.07317.94
5.5.290.0100.04718.07
5.5.280.0070.05020.87
5.5.270.0100.08320.97
5.5.260.0130.07020.96
5.5.250.0070.08720.68
5.5.240.0170.03020.19

preferences:
143.44 ms | 1394 KiB | 7 Q