3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Stress { const ABSENT = 0; // Ausente const SOFT = 1; // Ameno const MODERATE = 2; // Moderado const SEVERE = 3; // Severo const CRITICAL = 4; // Morte/Crítico const RATING = [ self::ABSENT => 'Ausência de estresse térmico', self::SOFT => 'Estresse térmico ameno', self::MODERATE => 'Estresse térmico moderado', self::SEVERE => 'Estresse térmico severo', self::CRITICAL => 'Estresse térmico crítico. Ocorrência de morte.', ]; const AMBIGUOUS = [ // Em 25 graus a 100% de UR temos um moderado: 250 => [ 100 => Stress::MODERATE ], // Já na linha dos 26,1 graus temos 3 ambíguos: 261 => [ 80 => Stress::SOFT, 90 => Stress::MODERATE, 100 => Stress::MODERATE ], // ... 433 => [ 30 => Stress::SEVERE ], 461 => [ 20 => Stress::MODERATE ], ]; public $temp;// int public $ur;// int public function __construct( $temp, $ur ) { $this->temp = $temp; $this->ur = $ur; } public function __toString() { $ambiguousRatingIndex = $this->getAmbiguousStressRatingIndex(); if ( $ambiguousRatingIndex !== false ) return sprintf( 'Classificação (por tabela de desambiguação): %s', self::RATING[ $ambiguousRatingIndex ] ); else { $rating = $this->getGeneralRatingIndex(); return sprintf( 'Classificação geral do estresse térmico por ausência de ambiguidade: %s', self::RATING[ $rating ] ); } } // Primeiro passo da lógica. Busca por ambiguidade: private function getAmbiguousStressRatingIndex() { $temp = $this->temp; $ur = $this->ur; if ( isset( self::AMBIGUOUS[ $temp ] ) && isset( self::AMBIGUOUS[ $temp ][ $ur ] ) ) return self::AMBIGUOUS[ $temp ][ $ur ];// int = índice do rótulo encontrado return false;// boolean false = não encontrou. Podia ser Exception, mas vamos facilitar o código } // Utilizado apenas após confirmada a ausência de ambiguidade // ITU = (0,8 x TA + (UR/100) x (TA-14,4) + 46,4) private function getGeneralRatingIndex() { $temp = $this->temp / 10;// Estávamos trabalhando com valores inteiros para a temperatura. 244 => 24.4 $ur = $this->ur / 100; $ITU = .8 * $temp + $ur * ( $temp - 14.4 ) + 46.4; if ( $ITU < 72 ) return Stress::ABSENT; if ( $ITU < 79 ) return Stress::SOFT; if ( $ITU < 90 ) return Stress::MODERATE; if ( $ITU < 98 ) return Stress::SEVERE; return Stress::CRITICAL; } } echo (string)( new Stress( 250, 100 ) ) . "\n";// 25,0 graus / 100% UR echo (string)( new Stress( 261, 80 ) ) . "\n";// 26,1 graus / 80% UR echo (string)( new Stress( 261, 90 ) ) . "\n";// 26,1 graus / 90% UR echo (string)( new Stress( 461, 20 ) ) . "\n";// 46,1 graus / 20% UR (seu exemplo) echo (string)( new Stress( 433, 30 ) ) . "\n";// 43,3 graus / 30% UR (seu exemplo) echo (string)( new Stress( 239, 40 ) ) . "\n"; echo (string)( new Stress( 317, 20 ) ) . "\n"; echo (string)( new Stress( 444, 80 ) ) . "\n";

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.0190.00316.88
8.3.60.0140.01016.75
8.3.50.0090.00617.92
8.3.40.0090.00618.69
8.3.30.0130.00918.70
8.3.20.0040.00424.18
8.3.10.0080.00024.66
8.3.00.0030.00626.16
8.2.180.0090.00925.92
8.2.170.0040.01119.08
8.2.160.0140.00022.96
8.2.150.0070.00025.66
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0040.00419.76
8.2.110.0090.00020.22
8.2.100.0060.00617.72
8.2.90.0040.00420.59
8.2.80.0030.00518.03
8.2.70.0030.00717.93
8.2.60.0040.00418.22
8.2.50.0080.00018.10
8.2.40.0060.00319.48
8.2.30.0000.00718.22
8.2.20.0050.00218.03
8.2.10.0060.00319.22
8.2.00.0040.00419.27
8.1.280.0080.00825.92
8.1.270.0000.00723.99
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0000.01023.81
8.1.230.0050.00520.95
8.1.220.0040.00417.77
8.1.210.0030.00619.07
8.1.200.0030.00617.35
8.1.190.0040.00417.35
8.1.180.0100.00018.10
8.1.170.0060.00318.64
8.1.160.0030.00319.07
8.1.150.0000.00718.93
8.1.140.0070.00018.95
8.1.130.0030.00317.46
8.1.120.0050.00317.49
8.1.110.0070.00017.48
8.1.100.0000.00717.45
8.1.90.0070.00017.48
8.1.80.0030.00417.40
8.1.70.0030.00317.49
8.1.60.0060.00317.63
8.1.50.0030.00617.46
8.1.40.0060.00317.54
8.1.30.0090.00017.63
8.1.20.0080.00017.65
8.1.10.0050.00317.64
8.1.00.0090.00017.39
8.0.300.0040.00419.95
8.0.290.0090.00516.58
8.0.280.0040.00418.47
8.0.270.0070.00017.95
8.0.260.0030.00316.72
8.0.250.0000.00816.88
8.0.240.0040.00416.92
8.0.230.0000.00716.96
8.0.220.0040.00416.88
8.0.210.0000.00716.94
8.0.200.0030.00316.87
8.0.190.0040.00417.00
8.0.180.0030.00516.89
8.0.170.0040.00416.93
8.0.160.0040.00416.96
8.0.150.0040.00416.73
8.0.140.0000.00716.83
8.0.130.0030.00313.36
8.0.120.0000.00716.83
8.0.110.0000.00816.96
8.0.100.0000.00716.86
8.0.90.0080.00016.91
8.0.80.0060.01216.83
8.0.70.0030.00316.96
8.0.60.0030.00516.96
8.0.50.0040.00416.74
8.0.30.0350.01016.81
8.0.20.0240.00916.91
8.0.10.0360.01217.02
8.0.00.0250.01216.87
7.4.330.0000.00515.55
7.4.320.0040.00416.61
7.4.300.0040.00416.43
7.4.290.0000.00716.48
7.4.280.0030.00616.38
7.4.270.0000.00716.51
7.4.260.0000.00613.24
7.4.250.0030.00316.63
7.4.240.0060.00116.51
7.4.230.0060.00316.49
7.4.220.0020.00616.56
7.4.210.0070.00716.65
7.4.200.0050.00316.51
7.4.160.0210.01116.49
7.4.150.0160.01116.36
7.4.140.0220.01316.34
7.4.130.0290.01316.15
7.4.120.0270.00716.14
7.4.110.0200.01116.37
7.4.100.0200.01016.41
7.4.90.0300.00616.41
7.4.80.0230.01516.29
7.4.70.0280.00416.22
7.4.60.0210.00716.23
7.4.50.0180.01116.24
7.4.40.0260.00916.16
7.4.30.0220.00616.43
7.4.20.0180.00916.23
7.4.10.0150.01316.38
7.4.00.0110.01516.46
7.3.330.0000.00816.33
7.3.320.0000.00813.42
7.3.310.0030.00316.35
7.3.300.0070.00016.41
7.3.290.0030.01216.42
7.3.280.0230.01016.29
7.3.270.0170.01216.28
7.3.260.0180.01116.27
7.3.250.0300.01516.27
7.3.240.0250.00716.27
7.3.230.0330.00016.27
7.3.220.0330.00416.23
7.3.210.0140.01916.11
7.3.200.0230.00716.13
7.3.190.0170.01316.06
7.3.180.0230.00716.16
7.3.170.0190.00816.13
7.3.160.0220.00716.23
7.3.150.0230.01116.28
7.3.140.0240.00516.21
7.3.130.0200.00816.25
7.3.120.0180.01116.22
7.3.110.0250.00016.09
7.3.100.0150.01116.16
7.3.90.0270.00016.56
7.3.80.0150.00916.20
7.3.70.0240.00416.29
7.3.60.0200.00716.36
7.3.50.0250.00716.40
7.3.40.0220.00716.39
7.3.30.0190.01116.43
7.3.20.0250.00616.40
7.3.10.0120.01816.37
7.3.00.0220.00716.33

preferences:
51.87 ms | 401 KiB | 5 Q