3v4l.org

run code in 300+ PHP versions simultaneously
<?php $mx = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], // [17, 18, 19, 20] ]; 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 = m-1; $this->c = 0; $this->d = n-1; $bCtr = ($this->b)/2; $dCtr = ($this->d)/2;; $this->mx = $mx; } public function rotate($r) { $k = 0; while(1) { $this->a += $k; $this->b -= $k; $this->c += $k; $this->d -= $k; 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--) { rotateSquare(); } ++$k; } } private function rotateSquare($k) { $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]; } $temp = []; for($i=0; $i<$this->m; ++$i) { for($j=0; $j<$this->n; ++$j) { $temp[$i + $t[$i][$j][0] ] [$j + $t[$i][$j][1] ] = $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.0100.00716.88
8.3.60.0070.00718.05
8.3.50.0070.01116.28
8.3.40.0100.00618.72
8.3.30.0070.00718.57
8.3.20.0060.00324.18
8.3.10.0040.00424.66
8.3.00.0030.00526.16
8.2.190.0070.01116.58
8.2.180.0150.00425.92
8.2.170.0150.00018.91
8.2.160.0070.01022.96
8.2.150.0050.00325.66
8.2.140.0080.00024.66
8.2.130.0000.00826.16
8.2.120.0040.00426.35
8.2.110.0100.00020.52
8.2.100.0080.00417.72
8.2.90.0060.00317.63
8.2.80.0050.00318.66
8.2.70.0050.00317.50
8.2.60.0040.00417.38
8.2.50.0030.00618.05
8.2.40.0030.00519.71
8.2.30.0000.00818.14
8.2.20.0040.00417.98
8.2.10.0060.00319.33
8.2.00.0000.00719.32
8.1.280.0040.01125.92
8.1.270.0080.00023.99
8.1.260.0040.00428.09
8.1.250.0050.00328.09
8.1.240.0050.00519.44
8.1.230.0060.00622.67
8.1.220.0000.00918.52
8.1.210.0000.00818.77
8.1.200.0030.00617.41
8.1.190.0070.00417.35
8.1.180.0040.00418.10
8.1.170.0030.00618.78
8.1.160.0000.00718.90
8.1.150.0040.00418.95
8.1.140.0040.00418.95
8.1.130.0070.00020.08
8.1.120.0050.00317.57
8.1.110.0040.00417.49
8.1.100.0000.00817.43
8.1.90.0050.00217.47
8.1.80.0040.00717.35
8.1.70.0000.00717.46
8.1.60.0000.00817.58
8.1.50.0030.00517.54
8.1.40.0040.00417.36
8.1.30.0060.00317.70
8.1.20.0080.00017.71
8.1.10.0060.00317.54
8.1.00.0060.00317.48
8.0.300.0030.00518.77
8.0.290.0000.00816.88
8.0.280.0040.00418.47
8.0.270.0000.00817.87
8.0.260.0030.00320.20
8.0.250.0000.00716.87
8.0.240.0080.00017.01
8.0.230.0000.00816.82
8.0.220.0000.00716.87
8.0.210.0000.00716.92
8.0.200.0070.00016.86
8.0.190.0040.00417.01
8.0.180.0000.00716.92
8.0.170.0060.00316.91
8.0.160.0000.00716.94
8.0.150.0000.00816.83
8.0.140.0040.00416.82
8.0.130.0000.00613.35
8.0.120.0040.00416.88
8.0.110.0070.00016.80
8.0.100.0000.00716.96
8.0.90.0040.00416.74
8.0.80.0030.01516.87
8.0.70.0020.00516.91
8.0.60.0030.00516.92
8.0.50.0000.00716.72
8.0.30.0140.00417.08
8.0.20.0100.00916.94
8.0.10.0040.00417.05
8.0.00.0130.00716.51
7.4.330.0000.00515.55
7.4.320.0030.00316.43
7.4.300.0030.00316.63
7.4.290.0040.00416.61
7.4.280.0080.00016.63
7.4.270.0100.00016.65
7.4.260.0000.00513.30
7.4.250.0000.00716.41
7.4.240.0060.00316.67
7.4.230.0080.00016.37
7.4.220.0040.00416.53
7.4.210.0070.00816.57
7.4.200.0000.00716.51
7.4.130.0090.00916.54
7.4.120.0030.01316.50
7.4.110.0100.01316.61
7.4.100.0130.00916.45
7.4.90.0150.00816.38
7.4.80.0140.00716.12
7.4.70.0070.01016.22
7.4.60.0070.01016.48
7.4.50.0100.00716.34
7.4.40.0040.01216.54
7.4.30.0070.01016.49
7.4.20.0030.01316.61
7.4.10.0110.00616.36
7.4.00.0070.01016.10
7.3.330.0040.00416.28
7.3.320.0050.00013.12
7.3.310.0030.00516.15
7.3.300.0000.00716.20
7.3.290.0080.01216.23
7.3.280.0020.01316.29
7.3.260.0100.01016.48
7.3.230.0070.01016.32
7.3.210.0100.00716.25
7.3.200.0130.00316.16
7.3.190.0110.00716.36
7.3.180.0110.00616.59
7.3.170.0040.01216.21
7.3.160.0060.00916.26
7.3.150.0110.00516.14
7.3.140.0080.00816.38
7.3.130.0060.00916.42
7.3.120.0100.00616.22
7.3.110.0160.00016.12
7.3.100.0030.01316.29
7.3.90.0030.01216.17
7.3.80.0100.00716.24
7.3.70.0060.00916.20
7.3.60.0100.00916.38
7.3.50.0060.01016.11
7.3.40.0060.00916.17
7.3.30.0120.00616.25
7.3.20.0070.01016.39
7.3.10.0140.00416.03
7.3.00.0040.01416.25
7.2.330.0060.01216.60
7.2.320.0130.00316.54
7.2.310.0100.00716.33
7.2.300.0060.01216.14
7.2.290.0100.00716.59
7.2.280.0100.00716.17
7.2.270.0100.00716.24
7.2.260.0080.00816.26
7.2.250.0060.01016.36
7.2.240.0110.00716.45
7.2.230.0040.01216.20
7.2.220.0070.01016.27
7.2.210.0040.01216.30
7.2.200.0040.01416.29
7.2.190.0100.01016.34
7.2.180.0110.00716.35
7.2.170.0040.01416.31
7.2.160.0030.01316.20
7.2.150.0150.00316.42
7.2.140.0130.00616.30
7.2.130.0140.00316.49
7.2.120.0140.00316.39
7.2.110.0090.00916.54
7.2.100.0070.01016.30
7.2.90.0100.00716.44
7.2.80.0090.00916.30
7.2.70.0100.00716.37
7.2.60.0110.00716.22
7.2.50.0060.01216.25
7.2.40.0070.01116.36
7.2.30.0040.01416.17
7.2.20.0100.00716.58
7.2.10.0430.01016.38
7.2.00.0070.01116.43

preferences:
54.47 ms | 401 KiB | 5 Q