3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class AbstractEmployee { protected $rank; protected $isBoss; public function __construct(int $rank, bool $isBoss) { $this->rank = $rank; $this->isBoss = $isBoss; } abstract function getBasicSalary(): float; abstract function getBasicCoffee(): float; abstract function getBasicPages(): float; public function getSalary(): float { $salary = $this->getBasicSalary(); if ($this->rank == 2) { $salary *= 1.25; } elseif ($this->rank == 3) { $salary *= 1.5; } if ($this->isBoss == true) { $salary *= 1.5; } return round($salary, 1); } public function getCoffee(): float { $coffee = $this->getBasicCoffee(); if ($this->isBoss == true) { $coffee *= 2; } return $coffee; } public function getPages(): float { $pages = $this->getBasicPages(); if ($this->isBoss == true) { $pages = 0; } return $pages; } } class Manager extends AbstractEmployee { public function getBasicSalary(): float { return 500; } public function getBasicCoffee(): float { return 20; } public function getBasicPages(): float { return 200; } } class Marketer extends AbstractEmployee { public function getBasicSalary(): float { return 400; } public function getBasicCoffee(): float { return 15; } public function getBasicPages(): float { return 150; } } class Engineer extends AbstractEmployee { public function getBasicSalary(): float { return 200; } public function getBasicCoffee(): float { return 5; } public function getBasicPages(): float { return 50; } } class Analyst extends AbstractEmployee { public function getBasicSalary(): float { return 800; } public function getBasicCoffee(): float { return 50; } public function getBasicPages(): float { return 5; } } class Department { private $name; private $employees = array(); public function __construct(string $name) { $this->name = $name; } public function addEmployees(int $count, string $profession, int $rank, bool $isBoss): void { if ($profession == "Manager") { for ($i = 0; $i < $count; $i++) { $this->employees[] = new Manager($rank, $isBoss); } } elseif ($profession == "Marketer") { for ($i = 0; $i < $count; $i++) { $this->employees[] = new Marketer($rank, $isBoss); } } elseif ($profession == "Engineer") { for ($i = 0; $i < $count; $i++) { $this->employees[] = new Engineer($rank, $isBoss); } } elseif ($profession == "Analyst") { for ($i = 0; $i < $count; $i++) { $this->employees[] = new Analyst($rank, $isBoss); } } } public function getInformation(): array { $information = array(); $information['name'] = $this->name; $information['employeesCount'] = count($this->employees); $information['selary'] = 0; $information['coffee'] = 0; $information['pages'] = 0; foreach ($this->employees as $employee) { $information['selary'] += $employee->getSalary(); $information['coffee'] += $employee->getCoffee(); $information['pages'] += $employee->getPages(); } return $information; } } class Vektor { private $departments = array(); public function addDepartment (Department $department): void { $this->departments[] = $department; } public function getDepartments(): array { return $this->departments; } public function getDepartmentsCount(): int { return count($this->departments); } } class Table { public function printTable (Vektor $vektor): void { $this->printLine("Департамент", "сотр.", "тугр.", "кофе", "стр.", "тугр/стр."); echo str_repeat("-", 70); echo "\n"; $employeesCount = 0; $totalSelary = 0; $totalCoffee = 0; $totalPages = 0; $totalSelarySharePages = 0; foreach ($vektor->getDepartments() as $department) { $employeesCount += $department->getInformation()['employeesCount']; $totalSelary += $department->getInformation()['selary']; $totalCoffee += $department->getInformation()['coffee']; $totalPages += $department->getInformation()['pages']; $totalSelarySharePages += $totalSelary / $totalPages; $this->printLine($department->getInformation()['name'], $department->getInformation()['employeesCount'], $department->getInformation()['selary'], $department->getInformation()['coffee'], $department->getInformation()['pages'], round($department->getInformation()['selary'] / $department->getInformation()['pages']), 1); } echo "\n"; $this->printLine("Среднее", round($employeesCount / $vektor->getDepartmentsCount(), 1), round($totalSelary / $vektor->getDepartmentsCount(), 1), round($totalCoffee / $vektor->getDepartmentsCount(), 1), round($totalPages / $vektor->getDepartmentsCount(), 1), round($totalSelarySharePages / $vektor->getDepartmentsCount(), 1)); $this->printLine("Всего", $employeesCount, $totalSelary, $totalCoffee, $totalPages, round($totalSelarySharePages, 1)); } private function printLine(string $title, $employees, $salary, $coffee, $pages, $salarySharePages): void { echo $this->padRight($title, 15); $this->padLeft($employees, 10) . $this->padLeft($salary, 10) . $this->padLeft($coffee, 10) . $this->padLeft($pages, 10) . $this->padLeft($salarySharePages, 15); echo "\n"; } private function padLeft ($field, int $col): void { echo str_repeat(" ", $col - mb_strlen($field)).$field; } private function padRight ($field, int $col) { echo $field.str_repeat(" ", $col - mb_strlen($field)); } } $procurementDepartment = new Department("Закупок"); $procurementDepartment->addEmployees(9, "Manager", 1, false); $procurementDepartment->addEmployees(3, "Manager", 2, false); $procurementDepartment->addEmployees(2, "Manager", 3, false); $procurementDepartment->addEmployees(2, "Marketer", 1, false); $procurementDepartment->addEmployees(1, "Manager", 2, true); $salesDepartment = new Department("Продаж"); $salesDepartment->addEmployees(12, "Manager", 1, false); $salesDepartment->addEmployees(6, "Marketer", 1, false); $salesDepartment->addEmployees(3, "Analyst", 1, false); $salesDepartment->addEmployees(2, "Analyst", 2, false); $salesDepartment->addEmployees(1, "Marketer", 2, true); $advertisingDepartment = new Department("Рекламы"); $advertisingDepartment->addEmployees(15, "Marketer", 1, false); $advertisingDepartment->addEmployees(10, "Marketer", 2, false); $advertisingDepartment->addEmployees(8, "Manager", 1, false); $advertisingDepartment->addEmployees(2, "Engineer", 1, false); $advertisingDepartment->addEmployees(1, "Marketer", 3, true); $logisticsDepartment = new Department("Логистики"); $logisticsDepartment->addEmployees(13, "Manager", 1, false); $logisticsDepartment->addEmployees(5, "Manager", 2, false); $logisticsDepartment->addEmployees(5, "Engineer", 1, false); $logisticsDepartment->addEmployees(1, "Manager", 1, true); $vektor = new Vektor(); $vektor->addDepartment($procurementDepartment); $vektor->addDepartment($salesDepartment); $vektor->addDepartment($advertisingDepartment); $vektor->addDepartment($logisticsDepartment); $table = new Table(); $table->printTable($vektor);

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.0100.01018.31
8.3.50.0060.00918.30
8.3.40.0100.01018.95
8.3.30.0030.01319.09
8.3.20.0050.00321.01
8.3.10.0090.00020.66
8.3.00.0090.00020.83
8.2.180.0090.00618.66
8.2.170.0140.00722.96
8.2.160.0110.00422.26
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0000.00820.08
8.2.110.0090.00020.78
8.2.100.0040.00918.16
8.2.90.0000.00820.71
8.2.80.0040.00418.05
8.2.70.0050.00518.30
8.2.60.0040.00418.47
8.2.50.0090.00018.10
8.2.40.0000.00819.67
8.2.30.0030.00619.38
8.2.20.0080.00018.24
8.2.10.0080.00019.70
8.2.00.0040.00418.19
8.1.280.0160.00625.92
8.1.270.0050.00320.53
8.1.260.0040.00426.35
8.1.250.0120.00328.09
8.1.240.0040.01523.86
8.1.230.0060.00621.16
8.1.220.0030.00618.04
8.1.210.0030.00519.29
8.1.200.0050.00517.60
8.1.190.0030.00617.64
8.1.180.0000.00918.10
8.1.170.0030.00618.84
8.1.160.0040.00419.05
8.1.150.0050.00319.07
8.1.140.0040.00420.38
8.1.130.0050.00320.36
8.1.120.0050.00317.68
8.1.110.0040.00417.57
8.1.100.0090.00317.63
8.1.90.0040.00417.55
8.1.80.0000.00917.57
8.1.70.0000.00817.66
8.1.60.0030.00617.78
8.1.50.0050.00517.67
8.1.40.0080.00017.75
8.1.30.0060.00317.80
8.1.20.0040.00417.88
8.1.10.0060.00317.90
8.1.00.0080.00017.77
8.0.300.0060.00320.13
8.0.290.0060.00317.00
8.0.280.0000.00918.71
8.0.270.0030.00617.14
8.0.260.0000.00718.63
8.0.250.0040.00417.24
8.0.240.0000.00717.12
8.0.230.0040.00417.18
8.0.220.0060.00317.30
8.0.210.0090.00017.20
8.0.200.0000.01117.16
8.0.190.0050.00317.28
8.0.180.0030.00617.13
8.0.170.0040.00417.27
8.0.160.0040.00417.15
8.0.150.0040.00417.05
8.0.140.0000.00817.16
8.0.130.0060.00013.63
8.0.120.0030.00617.09
8.0.110.0000.00917.23
8.0.100.0000.00817.28
8.0.90.0000.00817.19
8.0.80.0030.01317.25
8.0.70.0050.00317.22
8.0.60.0030.00617.29
8.0.50.0080.00017.10
8.0.30.0110.00917.35
8.0.20.0160.00517.40
8.0.10.0050.00317.05
8.0.00.0080.01717.01
7.4.330.0000.00515.55
7.4.320.0080.00016.82
7.4.300.0030.00316.79
7.4.290.0040.00416.80
7.4.280.0000.00816.61
7.4.270.0070.00316.72
7.4.260.0080.00016.80
7.4.250.0050.00516.84
7.4.240.0040.00416.77
7.4.230.0040.00416.70
7.4.220.0060.00316.50
7.4.210.0110.01016.88
7.4.200.0080.00016.84
7.4.160.0080.01016.71
7.4.140.0090.00917.86
7.4.130.0320.03216.72
7.4.120.0040.01416.68
7.4.110.0110.00816.58
7.4.100.0070.01716.65
7.4.90.0110.01116.56
7.4.80.0120.00619.39
7.4.70.0080.01116.67
7.4.60.0150.00916.70
7.4.50.0080.00816.55
7.4.40.0160.01416.71
7.4.00.0050.01015.07
7.3.330.0000.00613.49
7.3.320.0070.00013.42
7.3.310.0040.00416.56
7.3.300.0000.00816.51
7.3.290.0040.00416.41
7.3.280.0080.00916.57
7.3.260.0110.01416.71
7.3.240.0090.01216.60
7.3.230.0160.00316.68
7.3.210.0070.01116.77
7.3.200.0070.01116.64
7.3.190.0090.00916.86
7.3.180.0090.01216.65
7.3.170.0130.01016.50
7.3.160.0070.01116.58
7.3.120.0100.01015.25
7.3.110.0060.01214.67
7.3.100.0030.01315.21
7.3.90.0030.01215.11
7.3.80.0100.00715.14
7.3.70.0040.01215.02
7.3.60.0060.00915.11
7.3.50.0040.01114.81
7.3.40.0030.01314.91
7.3.30.0090.00314.97
7.3.20.0350.00615.49
7.3.10.0350.00915.40
7.3.00.0380.00815.56
7.2.330.0090.00917.07
7.2.320.0100.01416.95
7.2.310.0060.01216.89
7.2.300.0110.01416.66
7.2.290.0070.01016.87
7.2.250.0090.00915.44
7.2.240.0150.00615.43
7.2.230.0130.00315.24
7.2.220.0000.01215.39
7.2.210.0100.00015.05
7.2.200.0100.00715.19
7.2.190.0060.00914.98
7.2.180.0070.00715.29
7.2.170.0120.00415.14
7.2.150.0560.01015.24
7.2.140.0440.01215.07
7.2.130.0490.00515.05
7.2.120.0580.00515.08
7.2.110.0470.00815.26
7.2.100.0480.01115.21
7.2.90.0500.00815.04
7.2.80.0470.00715.14
7.2.70.0460.00915.21
7.2.60.0310.00815.08
7.2.50.0580.01015.05
7.2.40.0490.00415.34
7.2.30.0540.00715.24
7.2.20.0510.00915.33
7.2.10.0490.00915.20
7.2.00.0480.00715.08
7.1.330.0090.00615.81
7.1.320.0070.00315.86
7.1.310.0030.01315.98
7.1.300.0000.01215.55
7.1.290.0070.01115.86
7.1.280.0000.01015.77
7.1.270.0060.00615.84
7.1.260.0040.01515.83
7.1.250.0560.00514.21

preferences:
58.25 ms | 400 KiB | 5 Q