3v4l.org

run code in 300+ PHP versions simultaneously
<?php $matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], // [17, 18, 19, 20] ]; $r = 1; matrixRotation($matrix, $r); function matrixRotation($matrix, $r) { $m = new Matrix($matrix); $m->rotate(); // print_r($m->get()); } class Matrix { private $mx; private $m; private $n; private $a; // i [a,b] private $b; private $c; // j [c,d] private $d; public function get() { return $this->mx; } public function __construct($mx) { try { $this->set($mx); } catch(\Exception $e) { echo $e->getMessage(); // exit(1); } } private function set(array $mx) { $this->m = count($mx); $this->n = count($mx[0]); $this->a = 0; $this->b = $this->m-1; $this->c = 0; $this->d = $this->n-1; $this->mx = $mx; } public function rotate($r = 1) { $k = 0; while(1) { $this->a += $k; $this->b -= $k; $this->c += $k; $this->d -= $k; var_dump($this->a, $this->b,$this->c,$this->d); break; if ( $this->a === $this->b || $this->c === $this->d ) { break; } $mult = 2*($this->m-2*$k)+2*($this->n-2*$k)-4; $rm = $r % $mult; while($rm--) { print_r('rotateSquare'.PHP_EOL); // $this->rotateSquare(); } ++$k; } } private function rotateSquare() { $t = []; //transite for($i=0; $i<$this->m; ++$i) { for($j=0; $j<$this->n; ++$j) { $t[$i][$j] = [0,0]; } } $j=$this->c; for($i=$this->a; $i<$this->b; ++$i) { $t[$i][$j] = [-1,0]; } $i=$this->b; for($j=$this->c; $j<$this->d; ++$j) { $t[$i][$j] = [0,1]; } $j=$this->d; for($i=$this->b; $i>$this->a; --$i) { $t[$i][$j] = [1,0]; } $i=$this->a; for($j=$this->d; $j<$this->c; --$j) { $t[$i][$j] = [0,-1]; } prtint_r($t); // $temp = []; // for($i=0; $i<$this->m; ++$i) { // for($j=0; $j<$this->n; ++$j) { // $iOffset = $t[$i][$j][0]; // $jOffset = $t[$i][$j][1]; // $temp[$i+$iOffset][$j+$jOffset] = $this->mx[$i][$j]; // } // } // $this->mx = $this->ksort($temp); // return $this; } private function ksort($temp) { foreach($temp as &$ar){ ksort($ar); } ksort($temp); return $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.70.0070.01416.75
8.3.60.0040.01118.40
8.3.50.0160.00318.23
8.3.40.0060.00919.02
8.3.30.0140.00418.83
8.3.20.0030.00624.18
8.3.10.0080.00024.66
8.3.00.0040.00426.16
8.2.190.0100.01016.63
8.2.180.0140.00725.92
8.2.170.0070.01018.91
8.2.160.0030.01022.96
8.2.150.0000.00725.66
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0050.00326.35
8.2.110.0100.00019.39
8.2.100.0040.00817.97
8.2.90.0050.00319.41
8.2.80.0080.00517.35
8.2.70.0040.00417.73
8.2.60.0040.00417.75
8.2.50.0100.00018.05
8.2.40.0050.00319.89
8.2.30.0050.00318.19
8.2.20.0080.00018.15
8.2.10.0030.00519.34
8.2.00.0040.00419.33
8.1.280.0070.00725.92
8.1.270.0080.00023.99
8.1.260.0080.00028.09
8.1.250.0030.00528.09
8.1.240.0000.01022.06
8.1.230.0000.01120.89
8.1.220.0060.00317.74
8.1.210.0080.00018.97
8.1.200.0000.00817.52
8.1.190.0050.00317.34
8.1.180.0060.00318.10
8.1.170.0080.00018.50
8.1.160.0040.00419.00
8.1.150.0050.00218.93
8.1.140.0070.00019.00
8.1.130.0000.00720.22
8.1.120.0030.00617.55
8.1.110.0090.00017.49
8.1.100.0050.00317.51
8.1.90.0040.00417.50
8.1.80.0000.00717.48
8.1.70.0030.00317.52
8.1.60.0040.00417.61
8.1.50.0030.00617.54
8.1.40.0000.00817.57
8.1.30.0050.00317.68
8.1.20.0040.00417.60
8.1.10.0040.00417.63
8.1.00.0040.00417.46
8.0.300.0040.00420.18
8.0.290.0040.00416.75
8.0.280.0030.00618.43
8.0.270.0070.00017.98
8.0.260.0000.00620.16
8.0.250.0030.00316.98
8.0.240.0040.00417.00
8.0.230.0030.00516.89
8.0.220.0050.00316.90
8.0.210.0030.00316.89
8.0.200.0000.00717.01
8.0.190.0040.00417.07
8.0.180.0040.00417.05
8.0.170.0040.00416.99
8.0.160.0040.00417.00
8.0.150.0080.00016.90
8.0.140.0040.00416.89
8.0.130.0000.00613.47
8.0.120.0000.00717.00
8.0.110.0040.00416.98
8.0.100.0000.00716.98
8.0.90.0080.00016.91
8.0.80.0110.00716.98
8.0.70.0040.00416.89
8.0.60.0040.00416.79
8.0.50.0000.00817.07
8.0.30.0120.00316.85
8.0.20.0100.01016.95
8.0.10.0040.00417.13
8.0.00.0040.01617.05
7.4.330.0000.00515.55
7.4.320.0040.00416.66
7.4.300.0030.00316.55
7.4.290.0000.00716.63
7.4.280.0040.00416.55
7.4.270.0070.00416.68
7.4.260.0000.00513.37
7.4.250.0000.01016.49
7.4.240.0000.00716.63
7.4.230.0030.00316.63
7.4.220.0030.00516.67
7.4.210.0060.00916.62
7.4.200.0000.00716.70
7.4.130.0090.00916.53
7.4.120.0110.00816.42
7.4.110.0100.00716.71
7.4.100.0030.01716.41
7.4.90.0110.00616.56
7.4.80.0130.00816.33
7.4.70.0100.01016.31
7.4.60.0070.01016.56
7.4.50.0090.00916.32
7.4.40.0100.00616.24
7.4.30.0100.00716.64
7.4.20.0060.01016.35
7.4.10.0100.00616.57
7.4.00.0180.00616.09
7.3.330.0040.00416.53
7.3.320.0000.00513.30
7.3.310.0030.00316.44
7.3.300.0050.00316.44
7.3.290.0060.01116.38
7.3.280.0130.00616.34
7.3.260.0140.01116.68
7.3.230.0100.00716.56
7.3.210.0060.01016.41
7.3.200.0150.00316.39
7.3.190.0130.00416.56
7.3.180.0040.01216.57
7.3.170.0140.00416.46
7.3.160.0070.01016.60
7.3.150.0100.00716.51
7.3.140.0040.01216.60
7.3.130.0040.01416.45
7.3.120.0110.01116.52
7.3.110.0170.00716.38
7.3.100.0190.00016.42
7.3.90.0110.00916.51
7.3.80.0080.01216.62
7.3.70.0190.00816.34
7.3.60.0160.00416.43
7.3.50.0120.00816.41
7.3.40.0120.00716.44
7.3.30.0140.00516.47
7.3.20.0100.01016.57
7.3.10.0140.00616.39
7.3.00.0090.00916.62
7.2.330.0170.00316.51
7.2.320.0120.00916.72
7.2.310.0070.01016.77
7.2.300.0060.01016.68
7.2.290.0100.00716.98
7.2.280.0120.00616.78
7.2.270.0030.01416.82
7.2.260.0120.01216.56
7.2.250.0130.01016.43
7.2.240.0100.01016.39
7.2.230.0130.00616.87
7.2.220.0070.01416.61
7.2.210.0120.00816.75
7.2.200.0170.01016.61
7.2.190.0090.01216.65
7.2.180.0090.01216.50
7.2.170.0090.00916.62
7.2.160.0070.01216.72
7.2.150.0160.00516.76
7.2.140.0070.01316.66
7.2.130.0120.00816.67
7.2.120.0050.01316.67
7.2.110.0080.01116.74
7.2.100.0090.01116.74
7.2.90.0160.00416.64
7.2.80.0140.00516.66
7.2.70.0080.01116.70
7.2.60.0130.00716.77
7.2.50.0080.01216.63
7.2.40.0470.00716.80
7.2.30.0090.01216.72
7.2.20.0110.00816.56
7.2.10.0160.00416.65
7.2.00.0060.01316.67

preferences:
54.01 ms | 401 KiB | 5 Q