3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Case Battle Fairness | Round Validation $serverSeed = ''; // Server seed $eosBlockSeed = ''; // EOS Block Seed /* * This is the round number, where 1 round is one case opened. If the battle has 10 cases, * this means there are 10 rounds - 1-10. * IMPORTANT: If it's the tiebreaker round, it will always be totalRounds + 1 * because the tiebreaker is considered as one additional round. If you have 2 cases * which results in 2 rounds, the tiebreaker roundNumber is 3 because it's total (2) + 1. */ $roundNumber = -1; /* * Player position that we want to validate the roll for. * For example, if you want to validate your own roll and you were holding * the 3rd position from left to right, then playerPosition will be 3. */ $playerPosition = -1; // The Player Position (1 to 4) // Update this to true if you are validating a tiebreaker result. $isTiebreaker = false; /* * Case Ticket's Quantity, by default it's 100,000 * We only change this if there's a case that has different ticket distribution. * Right now, all cases use 100,000 by default. * IMPORTANT: If it's the tiebreaker round, this will be number of players participating on the tiebreaker. * For example, if two players are participating on a tiebreaker the ticketQuantity is 2. */ $ticketQuantity = 100000; /* ------------------ */ if ($serverSeed == '' || $eosBlockSeed == '' || $roundNumber < 0 || $playerPosition < 1 || $playerPosition > 4 || $ticketQuantity <= 0) { echo "Fill in details"; return; } define('MAX_HEX_SEGMENTS', 6); define('HEX_SEGMENT_SIZE', 2); define('BASE_FOR_HEX_CONVERSION', 256); define('HASH_TYPE', 'sha256'); function calculateDecimalValue(string $preResult): float { $decimalValue = 0; for ($i = 0; $i < MAX_HEX_SEGMENTS; $i++) { $hexValue = substr($preResult, HEX_SEGMENT_SIZE * $i, HEX_SEGMENT_SIZE); $decimalValue += hexdec($hexValue) / pow(BASE_FOR_HEX_CONVERSION, $i + 1); } return $decimalValue; } function getProvablyFairResult(string $init, int $qty): array { $preResult = hash(HASH_TYPE, $init); $decimalValue = calculateDecimalValue($preResult); $result = (int) ($decimalValue * $qty) + 1; return [ 'preResult' => $preResult, 'result' => $result, ]; } $serverSeed = preg_replace("/\r|\n/", "", $serverSeed); $eosBlockSeed = preg_replace("/\r|\n/", "", $eosBlockSeed); if ($isTiebreaker) { $stringToHash = "$serverSeed-$eosBlockSeed-$roundNumber"; } else { $stringToHash = "$serverSeed-$eosBlockSeed-$roundNumber-$playerPosition"; } $result = getProvablyFairResult($stringToHash, $ticketQuantity); echo "Result: {$result['result']}"; ?>

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.4.120.0080.00624.16
8.4.110.0240.00718.33
8.4.100.0300.00718.13
8.4.90.0270.00718.06
8.4.80.0270.00818.06
8.4.70.0300.00817.99
8.4.60.0300.00817.74
8.4.50.0310.00817.78
8.4.40.0300.00817.66
8.4.30.0360.00717.66
8.4.20.0290.00917.53
8.4.10.0300.00617.62
8.3.250.0150.00516.67
8.3.240.0200.00717.49
8.3.230.0280.00716.35
8.3.220.0220.00616.88
8.3.210.0270.00816.62
8.3.200.0260.00616.45
8.3.190.0240.00616.81
8.3.180.0220.00516.70
8.3.170.0280.00716.71
8.3.160.0300.00616.65
8.3.150.0280.00816.62
8.3.140.0280.00716.66
8.3.130.0250.00516.53
8.3.120.0250.00616.74
8.3.110.0220.00516.83
8.3.100.0260.00716.62
8.3.90.0280.00617.46
8.3.80.0270.00716.70
8.3.70.0290.00616.63
8.3.60.0260.00616.67
8.3.50.0260.00516.64
8.3.40.0260.00718.04
8.3.30.0220.00617.89
8.3.20.0230.00718.11
8.3.10.0240.00718.19
8.3.00.0200.00817.92
8.2.290.0250.00517.23
8.2.280.0240.00617.17
8.2.270.0280.00716.50
8.2.260.0260.00716.44
8.2.250.0240.00716.67
8.2.240.0220.00616.64
8.2.230.0240.00717.00
8.2.220.0220.00717.04
8.2.210.0220.00717.25
8.2.200.0220.00616.65
8.2.190.0260.00716.54
8.2.180.0250.00816.48
8.2.170.0300.00718.17
8.2.160.0280.00818.09
8.2.150.0270.00818.03
8.2.140.0270.00818.08
8.2.130.0240.00618.06
8.2.120.0270.00518.06
8.2.110.0250.00718.06
8.2.100.0260.00817.99
8.2.90.0270.00818.09
8.2.80.0260.00617.99
8.2.70.0250.00617.91
8.2.60.0240.00718.05
8.2.50.0260.00717.97
8.2.40.0280.00817.94
8.2.30.0240.00617.91
8.2.20.0230.00717.93
8.2.10.0220.00717.95
8.2.00.0250.00717.94
8.1.330.0240.00717.05
8.1.320.0260.00916.10
8.1.310.0240.00816.11
8.1.300.0250.00616.32
8.1.290.0230.00917.34
8.1.280.0260.00717.01
8.1.270.0240.00618.13
8.1.260.0210.00818.11
8.1.250.0240.00618.12
8.1.240.0220.00717.82
8.1.230.0200.00617.85
8.1.220.0220.00717.75
8.1.210.0240.00717.68
8.1.200.0250.00617.69
8.1.190.0200.00717.72
8.1.180.0240.00817.66
8.1.170.0230.00517.71
8.1.160.0240.00717.75
8.1.150.0200.00717.83
8.1.140.0240.00617.75
8.1.130.0220.00817.82
8.1.120.0250.00717.84
8.1.110.0240.00817.79
8.1.100.0230.00717.89
8.1.90.0220.00617.77
8.1.80.0220.00717.81
8.1.70.0230.00717.78
8.1.60.0260.00517.91
8.1.50.0230.00617.87
8.1.40.0230.00717.87
8.1.30.0230.00817.94
8.1.20.0250.00817.98
8.1.10.0240.00717.79
8.1.00.0230.00817.68

preferences:
26.93 ms | 403 KiB | 5 Q