3v4l.org

run code in 300+ PHP versions simultaneously
<?php class PseudoRandomSequence { const STATE_HASH = "sha512"; // 1/2 STATE_HASH block size, const STATE_SIZE = 32; private $state; public function __construct($state) { $this->state = $state; $this->mixState(); } public function int($min = 0, $max = PHP_INT_MAX) { $range = $max - $min; if ($range <= 0 || is_float($range)) { throw new Exception("Invalid min/max provided"); } $bits = 1; $tmp = $range; while ($tmp >>= 1) { $bits++; } $bytes = (int) max(ceil($bits / 8), 1); $mask = pow(2, $bits) - 1; do { $rand = $this->bytes($bytes); $result = hexdec(bin2hex($rand)) & $mask; } while ($result > $range); return $result + $min; } public function bytes($n) { $ret = ''; do { $ret .= $this->mixState(); } while (strlen($ret) < $n); return substr($ret, 0, $n); } private function mixState() { $hash = hash(self::STATE_HASH, $this->state, true); $this->state = substr($hash, 0, self::STATE_SIZE); return substr($hash, self::STATE_SIZE); } } $prng = new PseudoRandomSequence("test"); $answers = array_fill(0,100,0); $i = 0; $t1 = microtime(true); while ($i < 1000) { $answers[$prng->int(0,99)]++; $i++; } var_dump($answers); echo "\n".((microtime(true) - $t1) * 1000).'ms';

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)
7.3.120.0040.01414.86
7.3.110.0120.00614.62
7.3.100.0070.01314.55
7.3.90.0030.01615.06
7.3.80.0040.01114.59
7.3.70.0030.01514.98
7.3.60.0000.01714.87
7.3.50.0040.01814.89
7.3.40.0030.01414.86
7.3.30.0030.01714.77
7.3.20.0030.01716.84
7.3.10.0090.01516.67
7.3.00.0160.00316.64
7.2.240.0070.01015.05
7.2.230.0060.00615.00
7.2.220.0000.01914.91
7.2.210.0040.01115.18
7.2.200.0030.01415.18
7.2.190.0100.01014.89
7.2.180.0070.01315.04
7.2.170.0030.01614.93
7.2.160.0140.00815.11
7.2.150.0080.01617.02
7.2.140.0070.01117.01
7.2.130.0030.01517.07
7.2.120.0030.01717.03
7.2.110.0040.01516.95
7.2.100.0070.01316.68
7.2.90.0040.01817.01
7.2.80.0000.01816.96
7.2.70.0070.01316.87
7.2.60.0070.00716.87
7.2.50.0000.02017.00
7.2.40.0080.01116.85
7.2.30.0000.01416.89
7.2.20.0060.01217.00
7.2.10.0040.01617.15
7.2.00.0030.01417.01
7.1.330.0000.01215.87
7.1.320.0040.01415.91
7.1.310.0040.01115.75
7.1.300.0070.00715.79
7.1.290.0100.01016.02
7.1.280.0060.02015.65
7.1.270.0070.02015.78
7.1.260.0090.00915.88
7.1.250.0070.01315.86
7.1.70.0070.00717.10
7.1.60.0070.02319.50
7.1.50.0070.01816.70
7.1.00.0030.08022.54
7.0.200.1150.00714.87
7.0.140.0070.07722.10
7.0.60.0200.07019.88
7.0.50.0030.06017.81
7.0.40.0000.05020.30
7.0.30.0230.05020.26
7.0.20.0270.07720.23
7.0.10.0370.08020.15
7.0.00.0070.08720.16
5.6.280.0070.07721.09
5.6.210.0100.06720.71
5.6.200.0070.04318.18
5.6.190.0130.06320.54
5.6.180.0200.05320.42
5.6.170.0400.06720.61
5.6.160.0070.04020.57
5.6.150.0030.04318.17
5.6.140.0130.05018.22
5.6.130.0100.07318.24
5.6.120.0200.04021.15
5.6.110.0070.09321.00
5.6.100.0100.07721.00
5.6.90.0070.08720.96
5.6.80.0070.07020.41
5.6.70.0230.07720.39
5.5.350.0070.08720.51
5.5.340.0030.04318.08
5.5.330.0100.07020.25
5.5.320.0070.05020.41
5.5.310.0370.07320.32
5.5.300.0070.09017.92
5.5.290.0100.07317.95
5.5.280.0070.07020.70
5.5.270.0030.04720.80
5.5.260.0230.07720.66
5.5.250.0100.08720.68
5.5.240.0030.09320.13
5.4.450.0230.04719.49
5.4.440.0270.05719.34
5.4.430.0270.05719.27
5.4.420.0230.05319.21
5.4.410.0370.07319.39
5.4.400.0270.05019.20
5.4.390.0170.06718.99
5.4.380.0230.07318.84
5.4.370.0200.08018.87
5.4.360.0230.06319.18
5.4.350.0270.07719.04
5.4.340.0370.04318.86
5.4.320.0230.07319.09
5.4.310.0170.06718.95
5.4.300.0200.06319.22
5.4.290.0170.04719.16
5.4.280.0300.05019.21
5.4.270.0230.08019.22
5.4.260.0270.05318.87
5.4.250.0270.08019.19
5.4.240.0330.06319.16
5.4.230.0270.05019.08
5.4.220.0300.04719.21
5.4.210.0200.07319.29
5.4.200.0170.06019.14
5.4.190.0170.04019.30
5.4.180.0030.05018.96
5.4.170.0070.05319.21
5.4.160.0930.05719.11
5.4.150.0230.05718.85
5.4.140.0270.07716.36
5.4.130.0200.07716.36
5.4.120.0270.07016.36
5.4.110.0230.07016.59
5.4.100.0200.04716.56
5.4.90.0130.05016.52
5.4.80.0170.05716.25
5.4.70.0330.06316.45
5.4.60.0230.07316.35
5.4.50.0170.07316.50
5.4.40.0470.07016.55
5.4.30.0270.04716.57
5.4.20.0230.04016.27
5.4.10.0170.04316.25
5.4.00.0170.04715.98
5.3.290.0230.08314.83
5.3.280.0070.05714.61
5.3.270.0030.10014.61
5.3.260.1000.05014.64
5.3.250.2970.04014.70
5.3.240.2570.04014.62
5.3.230.2670.03014.63
5.3.220.2530.04714.52
5.3.210.2730.03714.82
5.3.200.2230.03714.56
5.3.190.2500.04014.59
5.3.180.2600.04014.57
5.3.170.2770.04314.81
5.3.160.2770.04714.50
5.3.150.2600.04014.50
5.3.140.2630.03314.55
5.3.130.2700.04014.58
5.3.120.2930.03714.72
5.3.110.2630.04714.68
5.3.100.2400.04014.14
5.3.90.2530.04014.27
5.3.80.2730.04014.04
5.3.70.2500.04014.09
5.3.60.2700.04314.00
5.3.50.2530.04014.09
5.3.40.2500.04313.97
5.3.30.2300.04013.84
5.3.20.2570.05013.94
5.3.10.2600.04013.82
5.3.00.0000.08313.66
5.2.170.1500.03311.26
5.2.160.2400.04011.18
5.2.150.2430.03311.08
5.2.140.2400.03311.18
5.2.130.2230.04311.21
5.2.120.2300.03311.04
5.2.110.2400.03011.30
5.2.100.2000.03711.10
5.2.90.2200.04311.04
5.2.80.2330.03711.20
5.2.70.2330.04711.07
5.2.60.2470.03711.09
5.2.50.2300.04311.10
5.2.40.1900.03310.93
5.2.30.1970.03010.92
5.2.20.1930.03010.96
5.2.10.1870.03710.79
5.2.00.2130.03710.71
5.1.60.1830.03010.09
5.1.50.1800.02710.27
5.1.40.1670.0309.91
5.1.30.2030.03710.35
5.1.20.2000.03310.33
5.1.10.2030.03010.17
5.1.00.1870.02710.18
5.0.50.0700.0338.55
5.0.40.0830.0208.41
5.0.30.0930.0378.41
5.0.20.1070.0238.41
5.0.10.0830.0208.41
5.0.00.1100.0378.41
4.4.90.1030.0208.41
4.4.80.0900.0138.41
4.4.70.0900.0108.41
4.4.60.0870.0178.41
4.4.50.0870.0138.41
4.4.40.0900.0208.41
4.4.30.0900.0138.41
4.4.20.1130.0178.41
4.4.10.0830.0178.41
4.4.00.0900.0238.41
4.3.110.0800.0178.41
4.3.100.1000.0178.41
4.3.90.1070.0208.41
4.3.80.0870.0278.41
4.3.70.0870.0138.41
4.3.60.1070.0178.41
4.3.50.0900.0108.41
4.3.40.1070.0208.41
4.3.30.0530.0278.41
4.3.20.0570.0308.41
4.3.10.0570.0178.41
4.3.00.0470.0138.41

preferences:
52.39 ms | 1761 KiB | 5 Q