3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); abstract class AbstractWorker{ public $rank; public $isBoss; public function __construct(int $rank, int $isBoss) { $this->rank = $rank; $this->isBoss = $isBoss; } public function getSalary(){ $salary = $this->getBasicSalary(); if ($this->rank == 2){ $salary *= 1.25; } elseif ($this->rank == 3){ $salary *= 1.5; } if ($this->isBoss == 1){ $salary *= 1.5; } return $salary; } public function getCoffee(){ $coffee = $this->getBasicCoffee(); if ($this->isBoss == 1){ $coffee *= 2; } return $coffee; } public function getPages(){ $pages = $this->getBasicPages(); if ($this->isBoss == 1){ $pages *= 0; } return $pages; } abstract function getBasicSalary(); abstract function getBasicCoffee(); abstract function getBasicPages(); } class Manager extends AbstractWorker{ public function getBasicSalary(){ return 500; } public function getBasicCoffee(){ return 20; } public function getBasicPages(){ return 200; } } class Marketer extends AbstractWorker{ public function getBasicSalary(){ return 400; } public function getBasicCoffee(){ return 15; } public function getBasicPages(){ return 150; } } class Engineer extends AbstractWorker{ public function getBasicSalary(){ return 200; } public function getBasicCoffee(){ return 5; } public function getBasicPages(){ return 50; } } class Analyst extends AbstractWorker{ public function getBasicSalary(){ return 800; } public function getBasicCoffee(){ return 50; } public function getBasicPages(){ return 5; } } class Department{ private $name; private $workers = array(); public function __construct(string $name) { $this->name = $name; } public function addWorker(AbstractWorker $worker){ $this->workers[] = $worker; } public function getNumberWorkers(){ return count($this->workers); } public function getDepartmentSalary(){ $totalSalary = 0; foreach ($this->workers as $worker) { $totalSalary += $worker->getSalary(); } return $totalSalary; } public function getDepartmentCoffee(){ $totalCoffee = 0; foreach ($this->workers as $worker) { $totalCoffee += $worker->getCoffee(); } return $totalCoffee; } public function getDepartmentPages(){ $totalPages = 0; foreach ($this->workers as $worker) { $totalPages += $worker->getPages(); } return $totalPages; } public function getDepartmentName(){ return $this->name; } public function addWorkersToDepartment(string $profession, int $count, int $rang, int $isBoss){ if ($profession == "Manager"){ for ($i = 0; $i < $count; $i++){ $this->addWorker(new Manager($rang, $isBoss)); } } elseif ($profession == "Marketer"){ for ($i = 0; $i < $count; $i++){ $this->addWorker(new Marketer($rang, $isBoss)); } } elseif ($profession == "Engineer"){ for ($i = 0; $i < $count; $i++){ $this->addWorker(new Engineer ($rang, $isBoss)); } } elseif ($profession == "Analyst"){ for ($i = 0; $i < $count; $i++){ $this->addWorker(new Analyst ($rang, $isBoss)); } } } } class Company{ private $departments = array(); public function addDepartment(Department $department){ $this->departments[] = $department; } public function getDepartments(){ return $this->departments; } public function getDepartmentCount(){ return count($this->departments); } } class Tabel{ private function padLeft($value, $columnLength){ echo $value; echo str_repeat(" ", $columnLength - mb_strlen($value)); } private function calculatiotOfOutput(array $informarion){ $col1 = 15; $col2 = 10; $col3 = 10; $col4 = 8; $col5 = 8; $col6 = 15; echo $this->padLeft($informarion["name"], $col1) . $this->padLeft($informarion["count"], $col2) . $this->padLeft($informarion["salary"], $col3) . $this->padLeft($informarion["coffee"], $col4) . $this->padLeft($informarion["pages"], $col5) . $this->padLeft($informarion["salaryDividePages"], $col6) . "\n"; } public function printTabel(Company $company){ $columnName = array("name" => "Департамент", "count" => "сотр.", "salary" => "тугр.", "coffee" => "кофе", "pages" => "стр.", "salaryDividePages" => "тугр./стр."); $this->calculatiotOfOutput($columnName); echo "\n"; $departmentInformation = array("name" => "", "count" => 0, "salary" => 0, "coffee" => 0, "pages" => 0, "salaryDividePages" => 0); foreach ($company->getDepartments() as $department) { $departmentInformation["name"] = $department->getDepartmentName(); $departmentInformation["count"] = $department->getNumberWorkers(); $departmentInformation["salary"] = $department->getDepartmentSalary(); $departmentInformation["coffee"] = $department->getDepartmentCoffee(); $departmentInformation["pages"] = $department->getDepartmentPages(); $departmentInformation["salaryDividePages"] = round($department->getDepartmentSalary() / $department->getDepartmentPages(), 1); $this->calculatiotOfOutput($departmentInformation); } echo "\n"; $totalInformation = array("name" => "Всего", "count" => 0, "salary" => 0, "coffee" => 0, "pages" => 0, "salaryDividePages" => 0); $totalInformation["name"] = "Всего"; foreach ($company->getDepartments() as $department) { $totalInformation["count"] += $department->getNumberWorkers(); $totalInformation["salary"] += $department->getDepartmentSalary(); $totalInformation["coffee"] += $department->getDepartmentCoffee(); $totalInformation["pages"] += $department->getDepartmentPages(); $totalInformation["salaryDividePages"] += round($department->getDepartmentSalary() / $department->getDepartmentPages(), 1); } $this->calculatiotOfOutput($totalInformation); $averageInformation = array("name" => "Среднее", "count" => round($totalInformation["count"] / $company->getDepartmentCount(), 1), "salary" => round($totalInformation["salary"] / $company->getDepartmentCount(), 1), "coffee" => round($totalInformation["coffee"] / $company->getDepartmentCount(), 1), "pages" => round($totalInformation["pages"] / $company->getDepartmentCount(), 1), "salaryDividePages" => round($totalInformation["salaryDividePages"] / $company->getDepartmentCount()), 1); $this->calculatiotOfOutput($averageInformation); } } $vektor = new Company; $tabel = new Tabel; $departmentOfProcurement = new Department("Закупок"); $departmentOfProcurement->addWorkersToDepartment("Manager", 9, 1, 0); $departmentOfProcurement->addWorkersToDepartment("Manager", 3, 2, 0); $departmentOfProcurement->addWorkersToDepartment("Manager", 2, 3, 0); $departmentOfProcurement->addWorkersToDepartment("Marketer", 2, 1, 0); $departmentOfProcurement->addWorkersToDepartment("Manager", 1, 2, 1); $departmentOfSales = new Department("Продаж"); $departmentOfSales->addWorkersToDepartment("Manager", 12, 1, 0); $departmentOfSales->addWorkersToDepartment("Marketer", 6, 1, 0); $departmentOfSales->addWorkersToDepartment("Analyst", 3, 1, 0); $departmentOfSales->addWorkersToDepartment("Analyst", 2, 2, 0); $departmentOfSales->addWorkersToDepartment("Marketer", 1, 2, 1); $departmentOfAdvertising = new Department("Рекламы"); $departmentOfAdvertising->addWorkersToDepartment("Marketer", 15, 1, 0); $departmentOfAdvertising->addWorkersToDepartment("Marketer", 10, 2, 0); $departmentOfAdvertising->addWorkersToDepartment("Manager", 8, 1, 0); $departmentOfAdvertising->addWorkersToDepartment("Engineer", 2, 1, 0); $departmentOfAdvertising->addWorkersToDepartment("Marketer", 1, 3, 1); $departmentOfLogistics = new Department("Логистики"); $departmentOfLogistics->addWorkersToDepartment("Manager", 13, 1, 0); $departmentOfLogistics->addWorkersToDepartment("Manager", 5, 2, 0); $departmentOfLogistics->addWorkersToDepartment("Engineer", 5, 1, 0); $departmentOfLogistics->addWorkersToDepartment("Manager", 1, 1, 1); $vektor->addDepartment($departmentOfProcurement); $vektor->addDepartment($departmentOfSales); $vektor->addDepartment($departmentOfAdvertising); $vektor->addDepartment($departmentOfLogistics); $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.0070.01116.88
8.3.50.0070.01018.60
8.3.40.0040.01118.84
8.3.30.0000.01518.88
8.3.20.0050.00320.41
8.3.10.0000.00823.79
8.3.00.0000.00823.69
8.2.180.0100.01025.92
8.2.170.0120.00618.95
8.2.160.0070.01522.96
8.2.150.0000.00825.66
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0000.00819.39
8.2.110.0030.00722.29
8.2.100.0090.00418.09
8.2.90.0000.00819.43
8.2.80.0040.00418.29
8.2.70.0040.00817.75
8.2.60.0080.00018.18
8.2.50.0040.00418.10
8.2.40.0040.00420.88
8.2.30.0000.00821.08
8.2.20.0030.00518.25
8.2.10.0030.00518.39
8.2.00.0030.00618.28
8.1.280.0090.00625.92
8.1.270.0080.00022.32
8.1.260.0000.00926.35
8.1.250.0080.00028.09
8.1.240.0060.00319.20
8.1.230.0060.00619.33
8.1.220.0040.00417.91
8.1.210.0060.00318.77
8.1.200.0030.00917.60
8.1.190.0060.00317.38
8.1.180.0050.00318.10
8.1.170.0000.00818.83
8.1.160.0000.00819.29
8.1.150.0000.00818.98
8.1.140.0040.00417.89
8.1.130.0000.00819.14
8.1.120.0080.00017.72
8.1.110.0000.00817.70
8.1.100.0000.00817.61
8.1.90.0040.00417.63
8.1.80.0000.00817.73
8.1.70.0070.00017.63
8.1.60.0000.00917.92
8.1.50.0030.00617.84
8.1.40.0040.00417.80
8.1.30.0030.00617.94
8.1.20.0040.00417.84
8.1.10.0040.00417.85
8.1.00.0050.00317.71
8.0.300.0040.00420.29
8.0.290.0000.00817.00
8.0.280.0000.00718.59
8.0.270.0040.00417.59
8.0.260.0040.00420.81
8.0.250.0040.00417.35
8.0.240.0050.00317.26
8.0.230.0000.00717.27
8.0.220.0000.00817.23
8.0.210.0040.00417.16
8.0.200.0000.00717.28
8.0.190.0000.00917.27
8.0.180.0030.00517.15
8.0.170.0080.00017.25
8.0.160.0060.00317.31
8.0.150.0080.00417.20
8.0.140.0060.00317.17
8.0.130.0030.00313.64
8.0.120.0030.00617.30
8.0.110.0030.00517.24
8.0.100.0030.00517.13
8.0.90.0030.00517.13
8.0.80.0090.00617.29
8.0.70.0060.00317.29
8.0.60.0030.00517.08
8.0.50.0040.00417.26
8.0.30.0120.01117.38
8.0.20.0110.01017.50
8.0.10.0050.00317.32
8.0.00.0140.00616.87
7.4.330.0000.00516.84
7.4.320.0040.00416.74
7.4.300.0030.00316.83
7.4.290.0040.00416.82
7.4.280.0000.00916.81
7.4.270.0040.00416.72
7.4.260.0000.00816.70
7.4.250.0030.00516.80
7.4.240.0080.00016.87
7.4.230.0030.00616.63
7.4.220.0110.00716.76
7.4.210.0110.00516.76
7.4.200.0040.00416.63
7.4.160.0090.00916.71
7.4.150.0100.01017.40
7.4.140.0070.01317.86
7.4.130.0130.00916.67
7.4.120.0110.01016.70
7.4.110.0130.00616.74
7.4.100.0130.01316.65
7.4.90.0150.00316.67
7.4.80.0120.00919.39
7.4.70.0140.01116.73
7.4.60.0030.01716.83
7.4.50.0100.00716.80
7.4.40.0110.00716.70
7.4.30.0060.01316.72
7.4.00.0080.01115.06
7.3.330.0050.00013.54
7.3.320.0030.00313.40
7.3.310.0080.00016.48
7.3.300.0020.00516.52
7.3.290.0030.00516.63
7.3.280.0080.01116.60
7.3.270.0130.00617.40
7.3.260.0060.01816.74
7.3.250.0080.01216.58
7.3.240.0110.00716.68
7.3.230.0140.00916.54
7.3.210.0120.00916.82
7.3.200.0090.00916.81
7.3.190.0050.01316.89
7.3.180.0030.01416.54
7.3.170.0120.00616.55
7.3.160.0040.01416.81
7.3.120.0060.01215.13
7.3.110.0090.01014.94
7.3.100.0060.00814.97
7.3.90.0070.00814.99
7.3.80.0070.00814.82
7.3.70.0030.01114.97
7.3.60.0090.00415.02
7.3.50.0050.00815.01
7.3.40.0060.00814.76
7.3.30.0070.00814.90
7.3.20.0070.00816.60
7.3.10.0090.00616.70
7.3.00.0030.01016.71
7.2.330.0090.00916.88
7.2.320.0110.00916.89
7.2.310.0030.02017.04
7.2.300.0080.01016.72
7.2.290.0160.01017.08
7.2.250.0050.01115.14
7.2.240.0060.01215.23
7.2.230.0110.00415.30
7.2.220.0030.00915.41
7.2.210.0020.01015.15
7.2.200.0070.00715.18
7.2.190.0030.01115.13
7.2.180.0070.00715.23
7.2.170.0070.00615.14
7.2.60.0060.00916.73
7.1.330.0060.00815.83
7.1.320.0040.01015.79
7.1.310.0050.00815.87
7.1.300.0040.01015.85
7.1.290.0030.00915.79
7.1.280.0060.00815.87
7.1.270.0050.00915.83
7.1.260.0060.00915.67
7.1.200.0140.00315.51
7.1.110.0260.01616.29
7.1.100.0290.01316.29
7.1.90.0240.01016.57
7.1.80.0290.01316.16
7.1.70.0360.01315.52
7.1.60.0350.00733.25
7.1.50.0330.01033.14
7.1.40.0360.00932.82
7.1.30.0450.00632.76
7.1.20.0400.01332.98
7.1.10.0230.01514.96
7.1.00.0340.00615.00
7.0.250.0310.00916.14
7.0.240.0300.01315.96
7.0.230.0200.01315.91
7.0.220.0290.01315.93
7.0.210.0350.01414.73
7.0.200.0200.01315.05
7.0.190.0170.01015.00
7.0.180.0160.01314.80
7.0.170.0380.01414.57
7.0.160.0240.01214.56
7.0.150.0420.01414.48
7.0.140.0290.00914.62
7.0.130.0350.01014.78
7.0.120.0340.00914.69
7.0.110.1260.01014.77
7.0.100.0370.00914.47
7.0.90.0390.00914.58
7.0.80.0250.00614.92
7.0.70.0370.00714.87
7.0.60.0270.00414.43
7.0.50.0360.00914.97
7.0.40.0200.01014.77
7.0.30.0290.01614.80
7.0.20.0230.00714.84
7.0.10.0230.01014.70
7.0.00.0340.00614.82

preferences:
39.3 ms | 400 KiB | 5 Q