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'; // We heated it, send it to the next pipe! return $next_pipe($water); }; // 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)
8.3.60.0120.00316.63
8.3.50.0150.00522.05
8.3.40.0060.00918.70
8.3.30.0110.00318.67
8.3.20.0040.00420.34
8.3.10.0050.00521.76
8.3.00.0090.00021.78
8.2.180.0150.00616.75
8.2.170.0040.01122.96
8.2.160.0100.01022.12
8.2.150.0080.00024.18
8.2.140.0060.00324.66
8.2.130.0040.00420.79
8.2.120.0000.00726.35
8.2.110.0050.00520.70
8.2.100.0120.00017.78
8.2.90.0080.00019.08
8.2.80.0060.00317.97
8.2.70.0000.00817.63
8.2.60.0000.00817.93
8.2.50.0080.00018.09
8.2.40.0060.00322.16
8.2.30.0000.00719.46
8.2.20.0060.00317.83
8.2.10.0050.00218.03
8.2.00.0040.00418.20
8.1.280.0140.00725.92
8.1.270.0030.00622.14
8.1.260.0080.00028.09
8.1.250.0080.00028.09
8.1.240.0060.00323.88
8.1.230.0040.00717.45
8.1.220.0040.00817.74
8.1.210.0030.00618.77
8.1.200.0140.00017.35
8.1.190.0000.00817.35
8.1.180.0040.00418.10
8.1.170.0000.00818.39
8.1.160.0040.00420.71
8.1.150.0000.00818.83
8.1.140.0030.00519.55
8.1.130.0000.00817.64
8.1.120.0040.00417.39
8.1.110.0000.00817.40
8.1.100.0040.00417.45
8.1.90.0040.00417.41
8.1.80.0030.00517.48
8.1.70.0030.00317.39
8.1.60.0040.00417.52
8.1.50.0040.00417.57
8.1.40.0080.00017.61
8.1.30.0030.00617.73
8.1.20.0030.00617.68
8.1.10.0040.00417.64
8.1.00.0040.00417.60
8.0.300.0000.00818.77
8.0.290.0060.00316.88
8.0.280.0050.00318.44
8.0.270.0030.00317.23
8.0.260.0000.00617.12
8.0.250.0070.00017.05
8.0.240.0070.00016.90
8.0.230.0000.00616.87
8.0.220.0050.00516.82
8.0.210.0050.00216.85
8.0.200.0000.00717.11
8.0.190.0050.00317.00
8.0.180.0070.00017.02
8.0.170.0040.00417.01
8.0.160.0000.00716.91
8.0.150.0000.00716.84
8.0.140.0040.00416.96
8.0.130.0030.00313.43
8.0.120.0030.00517.00
8.0.110.0000.00716.98
8.0.100.0040.00417.07
8.0.90.0040.00416.90
8.0.80.0060.00917.05
8.0.70.0000.00816.96
8.0.60.0080.00016.87
8.0.50.0040.00417.06
8.0.30.0090.00917.19
8.0.20.0100.00917.44
8.0.10.0070.00017.12
8.0.00.0100.00816.85
7.4.330.0000.00616.73
7.4.320.0030.00316.55
7.4.300.0070.00016.45
7.4.290.0030.00516.55
7.4.280.0040.00416.43
7.4.270.0000.00716.41
7.4.260.0080.00016.54
7.4.250.0050.00316.44
7.4.240.0050.00216.54
7.4.230.0030.00316.68
7.4.220.0060.01216.59
7.4.210.0080.00716.71
7.4.200.0000.00816.65
7.4.160.0090.00916.44
7.4.150.0090.00917.40
7.4.140.0130.00717.86
7.4.130.0020.01716.66
7.4.120.0050.01316.51
7.4.110.0080.00816.41
7.4.100.0090.00616.44
7.4.90.0030.01316.50
7.4.80.0070.01519.39
7.4.70.0130.00616.54
7.4.60.0110.00816.69
7.4.50.0030.01216.54
7.4.40.0180.00416.53
7.4.30.0150.00316.77
7.4.00.0120.00515.00
7.3.330.0070.00013.37
7.3.320.0050.00013.20
7.3.310.0030.00316.30
7.3.300.0000.00716.27
7.3.290.0000.00716.32
7.3.280.0080.00916.33
7.3.270.0060.01217.40
7.3.260.0130.00616.41
7.3.250.0110.00616.49
7.3.240.0150.00516.50
7.3.230.0120.00916.39
7.3.210.0160.00616.51
7.3.200.0100.00519.39
7.3.190.0130.00316.50
7.3.180.0100.00916.48
7.3.170.0060.01116.31
7.3.160.0040.01416.40
7.3.120.0090.00914.57
7.3.110.0090.00914.45
7.3.100.0100.00714.33
7.3.90.0080.00814.94
7.3.80.0080.00614.99
7.3.70.0000.01014.64
7.3.60.0000.01314.57
7.3.50.0090.00614.64
7.3.40.0120.00614.73
7.3.30.0030.00914.68
7.3.20.0000.00816.65
7.3.10.0000.01116.33
7.3.00.0060.00616.83
7.2.330.0090.00916.52
7.2.320.0090.00916.60
7.2.310.0040.01316.68
7.2.300.0060.01516.64
7.2.290.0080.00816.34
7.2.250.0070.01015.06
7.2.240.0070.01415.05
7.2.230.0030.01415.14
7.2.220.0090.00314.80
7.2.210.0070.00715.00
7.2.200.0000.01314.83
7.2.190.0100.00015.07
7.2.180.0070.01014.80
7.2.170.0100.01014.79
7.2.60.0100.00316.89
7.2.00.0000.01619.30
7.1.330.0060.01015.55
7.1.320.0110.00015.78
7.1.310.0060.00315.60
7.1.300.0060.00915.67
7.1.290.0000.01015.39
7.1.280.0040.01515.47
7.1.270.0030.00715.69
7.1.260.0090.00915.56
7.1.200.0030.00715.47
7.1.100.0100.00018.13
7.1.70.0040.00417.09
7.1.60.0190.00619.40
7.1.50.0000.01116.97
7.1.00.0030.07322.32
7.0.200.0030.00616.64
7.0.60.0100.03721.74
7.0.50.0130.06317.75
7.0.40.0100.03720.26
7.0.30.0200.05720.16
7.0.20.0230.05320.19
7.0.10.0130.06720.22
7.0.00.0030.09020.09
5.6.280.0030.03320.86
5.6.210.0100.07320.48
5.6.200.0100.05018.18
5.6.190.0030.04320.45
5.6.180.0370.07320.77
5.6.170.0170.05020.51
5.6.160.0070.07720.55
5.6.150.0100.08018.29
5.6.140.0070.04318.14
5.6.130.0100.03318.28
5.6.120.0130.07321.10
5.6.110.0070.08321.11
5.6.100.0070.05321.00
5.6.90.0100.07321.10
5.6.80.0000.07320.39
5.5.350.0170.07720.34
5.5.340.0100.04317.98
5.5.330.0100.04720.20
5.5.320.0600.06720.32
5.5.310.0270.05320.24
5.5.300.0100.07717.95
5.5.290.0000.08717.97
5.5.280.0100.03720.63
5.5.270.0000.09320.98
5.5.260.0100.08720.79
5.5.250.0030.07320.54
5.5.240.0200.07320.16

preferences:
53.18 ms | 401 KiB | 5 Q