3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); abstract class AbstractWorker { private $rank; private $isBoss; private $salary; private $coffee; abstract public function getBasicPages(): int; public function __construct(int $rank, bool $isBoss, int $salary, int $coffee) { $this->rank = $rank; $this->isBoss = $isBoss; $this->coffee = $coffee; $this->salary = $salary; } public function getRank(): int { return $this->rank; } public function setRank(int $rank): void { $this->rank = $rank; } public function getBoss(): bool { return $this->isBoss; } public function setBoss(bool $isBoss): void { $this->isBoss = $isBoss; } public function getSalary(): float { $modifiedSalary = $this->salary; if ($this->rank == 2){ $modifiedSalary *= 1.25; } elseif ($this->rank == 3){ $modifiedSalary *= 1.5; } if ($this->isBoss){ $modifiedSalary *= 1.5; } return $modifiedSalary; } public function getCoffee(): int { $modifiedCoffee = $this->coffee; if ($this->isBoss){ $modifiedCoffee *= 2; } return $modifiedCoffee; } public function getPages(): int { $pages = $this->getBasicPages(); if ($this->isBoss){ $pages = 0; } return $pages; } public function setSalary(float $salary): void { $this->salary = $salary; } public function setCoffee(int $coffee): void { $this->coffee = $coffee; } } class Manager extends AbstractWorker { public function getBasicPages(): int { return 200; } } class Marketer extends AbstractWorker { public function getBasicPages(): int { return 150; } } class Engineer extends AbstractWorker { public function getBasicPages(): int { return 50; } } class Analyst extends AbstractWorker { public function getBasicPages(): int { return 5; } } class Department { private $name; private $workers = array(); public function __construct(string $name) { $this->name = $name; } public function getName(): string { return $this->name; } public function addWorker(AbstractWorker $worker): void { $this->workers[] = $worker; } public function getNumberWorkers(): int { return count($this->workers); } public function getDepartmentSalary(): float { $totalSalary = 0; foreach ($this->workers as $worker) { $totalSalary += $worker->getSalary(); } return $totalSalary; } public function getDepartmentCoffee(): int { $totalCoffee = 0; foreach ($this->workers as $worker) { $totalCoffee += $worker->getCoffee(); } return $totalCoffee; } public function getDepartmentPages(): int { $totalPages = 0; foreach ($this->workers as $worker) { $totalPages += $worker->getPages(); } return $totalPages; } public function getDepartmentName(): string { return $this->name; } public function getWorkers(): array { return $this->workers; } public function getWorker(int $key): AbstractWorker { return $this->workers[$key]; } public function deleteWorker(int $key): void { unset($this->workers[$key]); } public function selectWorkers(string $profession): array { $workersOfCertainProfession = array(); foreach ($this->workers as $worker) { if (get_class($worker) == $profession && $worker->getBoss() == FALSE){ $workersOfCertainProfession[] = $worker; } } return $workersOfCertainProfession; } public function changeBoss(int $oldBoss, int $newBoss) { $this->workers[$oldBoss]->setBoss(FALSE); $this->workers[$newBoss]->setBoss(TRUE); } } class Company { private $departments = array(); public function addDepartment(Department $department): void { $this->departments[] = $department; } public function getDepartments(): array { return $this->departments; } public function getDepartmentCount(): int { return count($this->departments); } } class HiringWorkers { public function addWorkersToDepartment(Department $department, string $profession, int $count, int $rank, bool $isBoss, float $salary, int $coffee): void { if ($profession == Manager::class){ for ($i = 0; $i < $count; $i++){ $department->addWorker(new Manager($rank, $isBoss, $salary, $coffee)); } } elseif ($profession == Marketer::class){ for ($i = 0; $i < $count; $i++){ $department->addWorker(new Marketer($rank, $isBoss, $salary, $coffee)); } } elseif ($profession == Engineer::class){ for ($i = 0; $i < $count; $i++){ $department->addWorker(new Engineer ($rank, $isBoss, $salary, $coffee)); } } elseif ($profession == Analyst::class){ for ($i = 0; $i < $count; $i++){ $department->addWorker(new Analyst ($rank, $isBoss, $salary, $coffee)); } } else { throw new Exception("Введено ошибочное название профессии"); } } } class Tabel { public function printTabel(Company $company): void { $this->printRow("Департамент", "сотр.", "тугр.", "кофе", "стр", "тугр./стр."); echo "\n"; foreach ($company->getDepartments() as $department) { $this->printRow($department->getDepartmentName(), $department->getNumberWorkers(), $department->getDepartmentSalary(), $department->getDepartmentCoffee(), $department->getDepartmentPages(), round($department->getDepartmentSalary() / $department->getDepartmentPages(), 1)); } echo "\n"; $count = 0; $salary = 0; $coffee = 0; $pages = 0; $salaryDividePages = 0; foreach ($company->getDepartments() as $department) { $count += $department->getNumberWorkers(); $salary += $department->getDepartmentSalary(); $coffee += $department->getDepartmentCoffee(); $pages += $department->getDepartmentPages(); $salaryDividePages += round($salary / $pages, 1); } $this->printRow("Всего", $count, $salary, $coffee, $pages, $salaryDividePages); $this->printRow("Среднее", round($count / $company->getDepartmentCount(), 1), round($salary / $company->getDepartmentCount(), 1), round($coffee / $company->getDepartmentCount(), 1), round($pages / $company->getDepartmentCount(), 1), round($salaryDividePages / $company->getDepartmentCount(), 1)); echo "\n"; } private function padLeft($value, $columnLength): void { echo $value; echo str_repeat(" ", $columnLength - mb_strlen($value)); } private function printRow(string $name, $count, $salary, $coffee, $pages, $salaryDividePages): void { $col1 = 15; $col2 = 10; $col3 = 10; $col4 = 8; $col5 = 8; $col6 = 15; echo $this->padLeft($name, $col1) . $this->padLeft($count, $col2) . $this->padLeft($salary, $col3) . $this->padLeft($coffee, $col4) . $this->padLeft($pages, $col5) . $this->padLeft($salaryDividePages, $col6) . "\n"; } } class AnticrisisService { public function cutEngineers(Company $company): void { foreach ($company->getDepartments() as $department) { $workersOfCertainProfession = array(); $workersOfCertainProfession = $department->selectWorkers("Engineer"); if (count($workersOfCertainProfession) == 0){ continue; } do { $numberOfPermutations = 0; for ($i = 0; $i < count($workersOfCertainProfession) - 2; $i++){ if ($workersOfCertainProfession[$i]->getRank() == $workersOfCertainProfession[$i+1]){ $buf = $workersOfCertainProfession[$i]; $workersOfCertainProfession[$i] = $workersOfCertainProfession[$i+1]; $workersOfCertainProfession[$i+1] = $buf; $numberOfPermutations++; } } } while ($numberOfPermutations != 0); $workersOfCertainProfession = array_slice($workersOfCertainProfession, 0, ceil(count($workersOfCertainProfession) / 2.5)); var_dump($workersOfCertainProfession); foreach ($department->getWorkers() as $key => $worker) { if ($worker == $workersOfCertainProfession[0]){ $department->deleteWorker($key); unset($workersOfCertainProfession[0]); sort($workersOfCertainProfession); } } } } public function changeDataAnalytics(Company $company): void { foreach ($company->getDepartments() as $department) { $countOfBasicAnalyst = 0; $keyOfBestAnalyst = 0; $rankOfBestAnalyst = 0; $keyOfWorker = -1; foreach ($department->getWorkers() as $worker) { $keyOfWorker++; if ($worker instanceof Analyst){ $worker->setSalary(1100); $worker->setCoffee(75); if ($worker->getBoss() == FALSE){ $countOfBasicAnalyst++; if ($worker->getRank() > $rankOfBestAnalyst){ $rankOfBestAnalyst = $worker->getRank(); $keyOfBestAnalyst = $keyOfWorker; } } } } if (!($department->getWorker($department->getNumberWorkers()-1) instanceof Analyst) && $countOfBasicAnalyst > 0){ $department->changeBoss($department->getNumberWorkers()-1, $keyOfBestAnalyst); } } } public function increaseManagers(Company $company): void { foreach ($company->getDepartments() as $department) { $manager1RangCount = 0; $manager2RangCount = 0; foreach ($department->getWorkers() as $worker) { if ($worker instanceof Manager && ($worker->getRank() == 1)){ $manager1RangCount++; } elseif ($worker instanceof Manager && ($worker->getRank() == 2)){ $manager2RangCount++; } } $manager1RangCount = ceil($manager1RangCount / 2); $manager2RangCount = ceil($manager2RangCount / 2); foreach ($department->getWorkers() as $worker) { if($manager1RangCount + $manager2RangCount == 0){ break; } if ($worker instanceof Manager && $worker->getRank() == 1 && $manager1RangCount > 0){ $worker->setRank($worker->getRank()+1); $manager1RangCount--; } elseif ($worker instanceof Manager && $worker->getRank() == 2 && $manager2RangCount > 0) { $worker->setRank($worker->getRank()+1); $manager2RangCount--; } } } } } $vektor = new Company; $tabel = new Tabel; $hiringWorkers = new HiringWorkers; $departmentOfProcurement = new Department("Закупок"); $hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Manager", 9, 1, FALSE, 500, 20); $hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Manager", 3, 2, FALSE, 500, 20); $hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Manager", 2, 3, FALSE, 500, 20); $hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Marketer", 2, 1, FALSE, 400, 15); $hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Manager", 1, 2, TRUE, 500, 20); $departmentOfSales = new Department("Продаж"); $hiringWorkers->addWorkersToDepartment($departmentOfSales, "Manager", 12, 1, FALSE, 500, 20); $hiringWorkers->addWorkersToDepartment($departmentOfSales, "Marketer", 6, 1, FALSE, 400, 15); $hiringWorkers->addWorkersToDepartment($departmentOfSales, "Analyst", 3, 1, FALSE, 800, 50); $hiringWorkers->addWorkersToDepartment($departmentOfSales, "Analyst", 2, 2, FALSE, 800, 50); $hiringWorkers->addWorkersToDepartment($departmentOfSales, "Marketer", 1, 2, TRUE, 400, 15); $departmentOfAdvertising = new Department("Рекламы"); $hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Marketer", 15, 1, FALSE, 400, 15); $hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Marketer", 10, 2, FALSE, 400, 15); $hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Manager", 8, 1, FALSE, 500, 20); $hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Engineer", 2, 1, FALSE, 200, 5); $hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Marketer", 1, 3, TRUE, 400, 15); $departmentOfLogistics = new Department("Логистики"); $hiringWorkers->addWorkersToDepartment($departmentOfLogistics, "Manager", 13, 1, FALSE, 500, 20); $hiringWorkers->addWorkersToDepartment($departmentOfLogistics, "Manager", 5, 2, FALSE, 500, 20); $hiringWorkers->addWorkersToDepartment($departmentOfLogistics, "Engineer", 5, 1, FALSE, 200, 5); $hiringWorkers->addWorkersToDepartment($departmentOfLogistics, "Manager", 1, 1, TRUE, 500, 20); $vektor->addDepartment($departmentOfProcurement); $vektor->addDepartment($departmentOfSales); $vektor->addDepartment($departmentOfAdvertising); $vektor->addDepartment($departmentOfLogistics); $anticrisisService = new AnticrisisService; $anticrisisService->increaseManagers($vektor); $tabel->printTabel($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.00618.43
8.3.50.0070.01516.43
8.3.40.0120.00319.21
8.3.30.0130.00319.02
8.3.20.0090.00019.03
8.3.10.0080.00023.60
8.3.00.0030.00619.38
8.2.180.0160.00618.13
8.2.170.0110.00422.96
8.2.160.0090.00619.35
8.2.150.0080.00024.18
8.2.140.0030.00624.66
8.2.130.0040.00419.76
8.2.120.0040.00426.35
8.2.110.0070.00321.12
8.2.100.0060.00618.03
8.2.90.0060.00319.47
8.2.80.0000.00817.97
8.2.70.0060.00318.40
8.2.60.0060.00318.30
8.2.50.0030.00518.41
8.2.40.0040.00420.88
8.2.30.0040.00419.50
8.2.20.0040.00418.28
8.2.10.0030.00518.34
8.2.00.0030.00618.51
8.1.280.0100.00725.92
8.1.270.0070.00420.08
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0060.00319.89
8.1.230.0100.00318.20
8.1.220.0030.00618.03
8.1.210.0040.00418.77
8.1.200.0030.00617.73
8.1.190.0050.00517.60
8.1.180.0060.00318.10
8.1.170.0030.00518.97
8.1.160.0050.00319.09
8.1.150.0030.00520.79
8.1.140.0000.00719.34
8.1.130.0030.00619.34
8.1.120.0080.00017.75
8.1.110.0040.00417.70
8.1.100.0040.00417.73
8.1.90.0000.00917.76
8.1.80.0030.00717.62
8.1.70.0050.00317.74
8.1.60.0090.00017.92
8.1.50.0000.00817.79
8.1.40.0040.00417.86
8.1.30.0040.00418.04
8.1.20.0030.00618.03
8.1.10.0030.00617.82
8.1.00.0030.00617.70
8.0.300.0000.00818.77
8.0.290.0040.00717.13
8.0.280.0000.00818.79
8.0.270.0060.00617.54
8.0.260.0000.00717.67
8.0.250.0030.00617.35
8.0.240.0030.00717.32
8.0.230.0050.00317.37
8.0.220.0030.00717.33
8.0.210.0000.00717.23
8.0.200.0030.00317.33
8.0.190.0000.00817.35
8.0.180.0000.00917.29
8.0.170.0030.00617.33
8.0.160.0000.00817.21
8.0.150.0040.00417.25
8.0.140.0000.00817.22
8.0.130.0060.00013.76
8.0.120.0050.00317.29
8.0.110.0000.00817.34
8.0.100.0030.00517.11
8.0.90.0000.00817.29
8.0.80.0140.00317.33
8.0.70.0040.00417.36
8.0.60.0050.00317.19
8.0.50.0000.00817.30
8.0.30.0120.00817.33
8.0.20.0130.01317.46
8.0.10.0000.00817.14
8.0.00.0110.01117.15
7.4.330.0030.00315.55
7.4.320.0050.00216.81
7.4.300.0000.00816.89
7.4.290.0070.00016.80
7.4.280.0040.00416.82
7.4.270.0050.00516.88
7.4.260.0030.00516.92
7.4.250.0030.00516.66
7.4.240.0040.00416.83
7.4.230.0040.00416.59
7.4.220.0040.00416.97
7.4.210.0040.01416.66
7.4.200.0030.00516.64
7.4.160.0090.01116.75
7.4.150.0160.01017.40
7.4.140.0130.01217.86
7.4.130.0060.01316.90
7.4.120.0110.01316.77
7.4.110.0100.01016.85
7.4.100.0100.01316.67
7.4.90.0090.00916.61
7.4.80.0130.00619.39
7.4.70.0030.01716.79
7.4.60.0060.01116.75
7.4.50.0000.01416.94
7.4.40.0160.00616.83
7.4.10.0070.01315.08
7.4.00.0060.01115.15
7.3.330.0030.00313.43
7.3.320.0000.00613.46
7.3.310.0040.00416.54
7.3.300.0040.00416.53
7.3.290.0100.00716.64
7.3.280.0110.00916.64
7.3.270.0120.01217.40
7.3.260.0130.01016.82
7.3.250.0090.01416.71
7.3.240.0130.00816.68
7.3.230.0110.01116.64
7.3.210.0060.01316.92
7.3.200.0070.01916.57
7.3.190.0170.00616.93
7.3.180.0110.01116.65
7.3.170.0080.01116.70
7.3.160.0140.01216.97
7.3.130.0030.01615.18
7.3.120.0110.00714.82
7.3.110.0000.01615.03
7.3.100.0080.00814.72
7.3.90.0090.00615.38
7.3.80.0150.00314.80
7.3.70.0090.00915.07
7.3.60.0000.01515.04
7.3.50.0060.00915.06
7.3.40.0120.00314.91
7.3.30.0080.01215.05
7.3.20.0040.01116.33
7.3.10.0020.01016.79
7.3.00.0080.00416.70
7.2.330.0080.01916.88
7.2.320.0060.01216.88
7.2.310.0090.01116.95
7.2.300.0130.00716.66
7.2.290.0160.00816.98
7.2.260.0090.00915.35
7.2.250.0030.01215.46
7.2.240.0000.01515.50
7.2.230.0080.00815.40
7.2.220.0070.00315.37
7.2.210.0070.01015.39
7.2.200.0070.00315.15
7.2.190.0060.00915.46
7.2.180.0030.00615.28
7.2.170.0050.00515.36
7.2.160.0030.00615.38
7.2.150.0130.00316.89
7.2.140.0090.00617.00
7.2.130.0050.01017.00
7.2.120.0030.01117.02
7.2.110.0030.00916.95
7.2.100.0050.00916.73
7.2.90.0020.01016.84
7.2.80.0070.00517.04
7.2.70.0110.00317.01
7.2.60.0040.00816.91
7.2.50.0090.00916.91
7.2.40.0100.00317.13
7.2.30.0070.00816.96
7.2.20.0070.00916.87
7.2.10.0110.00917.35
7.2.00.0110.01117.17
7.1.330.0080.00415.91
7.1.320.0000.00916.04
7.1.310.0070.01115.96
7.1.300.0030.00615.66
7.1.290.0070.00715.84
7.1.280.0090.00615.85
7.1.270.0030.00615.71
7.1.260.0060.00915.59
7.1.250.0070.00715.74
7.1.240.0130.00316.06
7.1.230.0030.01015.91
7.1.220.0030.00615.58
7.1.210.0120.00315.80
7.1.200.0070.00815.79
7.1.190.0100.00615.99
7.1.180.0090.00615.83
7.1.170.0090.00615.94
7.1.160.0110.00315.93
7.1.150.0090.00915.97
7.1.140.0070.01515.80
7.1.130.0120.01016.59
7.1.120.0160.00616.59
7.1.110.0190.00515.97
7.1.100.0130.00716.36
7.1.90.0120.00716.13
7.1.80.0110.01116.31
7.1.70.0110.01015.71
7.1.60.0210.00824.54
7.1.50.0250.00524.60
7.1.40.0190.01324.37
7.1.30.0250.01024.38
7.1.20.0160.01724.38
7.1.10.0120.00715.43
7.1.00.0150.00915.49
7.0.330.0040.01115.13
7.0.320.0080.00415.46
7.0.310.0070.00715.38
7.0.300.0000.01615.17
7.0.290.0070.00715.46
7.0.280.0000.01815.54
7.0.270.0070.00715.34
7.0.260.0030.01415.47
7.0.250.0040.01115.49
7.0.240.0000.01215.65
7.0.230.0000.01315.46
7.0.220.0120.00015.54
7.0.210.0110.00015.41
7.0.200.0060.00615.38
7.0.190.0040.01115.38
7.0.180.0120.00315.31
7.0.170.0080.00815.50
7.0.160.0030.00715.44
7.0.150.0030.00615.59
7.0.140.0130.00015.35
7.0.130.0040.00415.51
7.0.120.0000.01115.42
7.0.110.0040.01115.45
7.0.100.0080.00815.57
7.0.90.0030.00715.56
7.0.80.0060.00615.37
7.0.70.0100.00315.60
7.0.60.0120.00315.16
7.0.50.0030.00915.43
7.0.40.0120.00313.49
7.0.30.0040.00413.23
7.0.20.0120.00313.18
7.0.10.0090.00613.56
7.0.00.0120.00613.45
5.6.400.0030.00713.94
5.6.390.0040.00813.96
5.6.380.0000.01214.37
5.6.370.0110.00014.07
5.6.360.0030.01414.24
5.6.350.0040.00414.08
5.6.340.0120.00914.11
5.6.330.0060.00914.38
5.6.320.0100.00314.29
5.6.310.0040.01213.88
5.6.300.0060.00614.21
5.6.290.0040.01114.32
5.6.280.0030.01014.48
5.6.270.0030.01214.26
5.6.260.0070.01014.32
5.6.250.0030.00714.23
5.6.240.0030.01014.07
5.6.230.0060.00314.26
5.6.220.0040.00714.37
5.6.210.0000.01214.22
5.6.200.0070.00714.31
5.6.190.0090.00014.08
5.6.180.0110.00313.96
5.6.170.0000.01114.40
5.6.160.0080.00614.31
5.6.150.0070.01014.27
5.6.140.0040.00714.13
5.6.130.0030.00714.20
5.6.120.0120.00313.93
5.6.110.0080.00414.06
5.6.100.0070.00314.02
5.6.90.0060.00614.00
5.6.80.0040.00713.96
5.6.70.0000.01314.05
5.6.60.0040.01114.09
5.6.50.0070.01014.09
5.6.40.0030.00613.83
5.6.30.0040.00714.17
5.6.20.0040.00414.10
5.6.10.0090.00014.20
5.6.00.0070.00714.02

preferences:
65.44 ms | 400 KiB | 5 Q