3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * Fill in all four below and click the blue 'eval();' button. * ------------------ */ $unhashedServerSeed = 'e2acec00fc997ad5f6845b0be1a7a711655ad4afc5aacfbc5ab7cb00ffe922a1'; $nonce = 305; $clientSeed = 'nya4CvRf2syWfc5n9EirGvJv2ZrYbhv9'; $ticketQuantity = -1; /* ------------------ */ if ($unhashedServerSeed == '' || $nonce < 0 || $clientSeed == '' || $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, string $serverSeed, int $qty): array { $preResult = hash_hmac(HASH_TYPE, $init, $serverSeed); $decimalValue = calculateDecimalValue($preResult); $result = (int) ($decimalValue * $qty) + 1; return [ 'preResult' => $preResult, 'result' => $result, ]; } $unhashedServerSeed = preg_replace( "/\r|\n/", "", $unhashedServerSeed); $clientSeed = preg_replace( "/\r|\n/", "", $clientSeed); $nrand = strlen($clientSeed); $stringToHash = "$clientSeed-$nrand-$nonce"; $result = getProvablyFairResult($stringToHash, $unhashedServerSeed, $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.5.30.0090.00819.66
8.5.20.0110.00819.84
8.5.10.0300.01016.42
8.5.00.0230.00916.49
8.4.180.0130.00919.46
8.4.170.0170.00719.51
8.4.160.0270.01120.42
8.4.150.0310.01119.41
8.4.140.0360.00717.51
8.4.130.0380.00517.46
8.4.120.0390.00917.81
8.4.110.0380.00817.63
8.4.100.0390.01017.59
8.4.90.0350.01117.84
8.4.80.0370.00917.69
8.4.70.0370.00917.68
8.4.60.0380.00817.64
8.4.50.0380.00717.77
8.4.40.0440.01017.41
8.4.30.0360.01217.63
8.4.20.0420.00817.60
8.4.10.0390.00917.50
8.3.300.0130.00820.13
8.3.290.0340.00718.31
8.3.280.0300.01118.37
8.3.270.0370.00916.38
8.3.260.0390.00516.55
8.3.250.0350.00916.66
8.3.240.0370.00616.50
8.3.230.0340.00916.62
8.3.220.0370.00716.19
8.3.210.0380.00916.87
8.3.200.0400.00516.52
8.3.190.0390.00516.77
8.3.180.0350.00916.73
8.3.170.0400.00816.42
8.3.160.0450.01016.56
8.3.150.0390.00716.58
8.3.140.0370.00916.66
8.3.130.0350.00916.48
8.3.120.0360.00616.64
8.3.110.0340.00616.79
8.3.100.0370.00916.60
8.3.90.0360.01016.54
8.3.80.0410.00816.65
8.3.70.0400.00916.60
8.3.60.0390.00716.68
8.3.50.0380.01016.50
8.3.40.0360.00917.69
8.3.30.0300.00717.85
8.3.20.0290.00717.59
8.3.10.0280.00817.74
8.3.00.0280.00917.82

preferences:
37.63 ms | 403 KiB | 5 Q