3v4l.org

run code in 500+ PHP versions simultaneously
<?php /* * Fill in all five below and click the blue 'eval();' button. * ------------------ */ $numberOfCase = 3; $unhashedServerSeed = 'ec385c144f6ecc715adf3e96ccadda4245f4aeaec75fcd6240a95abe6c2b22f7'; $nonce = 1; $clientSeed = '1'; $qty = 1; /* ------------------ */ if ($numberOfCase < 0 || $unhashedServerSeed == '' || $nonce < 0 || $clientSeed == '' || $qty <= 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); $stringToHash = "$clientSeed-$numberOfCase-$nonce"; $result = getProvablyFairResult($stringToHash, $unhashedServerSeed, $qty); 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.80.0290.01117.15
8.5.70.0340.01016.98
8.5.60.0370.00516.86
8.5.50.0360.00416.77
8.5.40.0350.00716.93
8.5.30.0340.00716.83
8.5.20.0390.00616.79
8.5.10.0330.00616.73
8.5.00.0070.01217.14
8.4.230.0150.01019.96
8.4.220.0270.01520.03
8.4.210.0310.01419.70
8.4.200.0300.01019.87
8.4.190.0380.00719.87
8.4.180.0340.00819.86
8.4.170.0290.00719.84
8.4.160.0230.01019.76
8.4.150.0330.01219.95
8.4.140.0350.01317.84
8.4.130.0280.01018.00
8.4.120.0260.00317.96
8.4.110.0170.00418.14
8.4.100.0300.01118.15
8.4.90.0360.01017.96
8.4.80.0370.00917.98
8.4.70.0350.01018.09
8.4.60.0370.01018.06
8.4.50.0280.01318.03
8.4.40.0310.01217.90
8.4.30.0330.01217.86
8.4.20.0320.00717.93
8.4.10.0430.00618.05
8.3.320.0330.01018.59
8.3.310.0320.00918.70
8.3.300.0360.01018.40
8.3.290.0340.00718.54
8.3.280.0210.00618.62
8.3.270.0260.00716.93
8.3.260.0290.00816.86
8.3.250.0340.00816.78
8.3.240.0310.01116.98
8.3.230.0330.00516.98
8.3.220.0170.00316.91
8.3.210.0200.00316.78
8.3.200.0330.00916.70
8.3.190.0330.00916.97
8.3.180.0350.00717.04
8.3.170.0370.01016.84
8.3.160.0390.00816.71
8.3.150.0360.00816.75
8.3.140.0350.01016.78
8.3.130.0300.00617.01
8.3.120.0310.00816.79
8.3.110.0280.01117.04
8.3.100.0280.00917.04
8.3.90.0270.01316.83
8.3.80.0330.01016.89
8.3.70.0350.01016.91
8.3.60.0290.00617.00
8.3.50.0380.00916.75
8.3.40.0400.00817.91
8.3.30.0290.00818.16
8.3.20.0260.01118.35
8.3.10.0270.00618.33
8.3.00.0260.00418.34
8.2.320.0350.00718.07
8.2.310.0320.00918.17

preferences:
47.29 ms | 762 KiB | 5 Q