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 = 0; $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.10.0040.01116.88
7.3.00.0140.00516.75
7.2.130.0080.00817.02
7.2.120.0030.01017.01
7.2.110.0130.00617.16
7.2.100.0030.01216.66
7.2.90.0070.01017.07
7.2.80.0030.01416.62
7.2.70.0000.01716.58
7.2.60.0060.01017.04
7.2.50.0000.01716.96
7.2.40.0100.00716.81
7.2.30.0030.01017.05
7.2.20.0040.01217.14
7.2.10.0100.00617.06
7.2.00.0030.01417.08
7.1.250.0060.00915.53
7.1.70.0100.00317.19
7.1.60.0060.02219.50
7.1.50.0060.01916.95
7.1.00.0070.07722.36
7.0.200.0860.01014.70
7.0.140.0070.07722.00
7.0.60.0200.08019.96
7.0.50.0100.08317.92
7.0.40.0130.06720.18
7.0.30.0370.06720.23
7.0.20.0200.08320.30
7.0.10.0400.08320.20
7.0.00.0100.08720.10
5.6.280.0130.09321.16
5.6.210.0030.08020.51
5.6.200.0100.04018.27
5.6.190.0100.09020.61
5.6.180.0370.05720.25
5.6.170.0500.07320.47
5.6.160.0070.04020.41
5.6.150.0000.04718.28
5.6.140.0030.05718.12
5.6.130.0030.07718.14
5.6.120.0100.03721.00
5.6.110.0070.09021.01
5.6.100.0170.07321.04
5.6.90.0070.09321.13
5.6.80.0070.08720.40
5.6.70.0230.07020.38
5.5.350.0170.07020.34
5.5.340.0030.04718.05
5.5.330.0070.09320.35
5.5.320.0170.03720.41
5.5.310.0300.07020.32
5.5.300.0100.09018.04
5.5.290.0070.08317.98
5.5.280.0030.04720.82
5.5.270.0130.07320.77
5.5.260.0200.06720.69
5.5.250.0170.06320.54
5.5.240.0070.07720.24
5.4.450.0670.06319.32
5.4.440.0970.06019.54
5.4.430.0670.06019.41
5.4.420.0130.07019.43
5.4.410.0130.05719.15
5.4.400.0370.05718.53
5.4.390.0300.06018.75
5.4.380.0330.07018.61
5.4.370.0200.07318.58
5.4.360.0370.05318.61
5.4.350.0400.06318.70
5.4.340.0470.05318.79
5.4.320.0370.05718.78
5.4.310.0370.05318.76
5.4.300.0330.06018.77
5.4.290.0400.05318.77
5.4.280.0270.06318.75
5.4.270.0200.07718.74
5.4.260.0370.08718.79
5.4.250.0270.06318.73
5.4.240.0570.05018.59
5.4.230.0200.07318.59
5.4.220.0500.05718.72
5.4.210.0270.06718.46
5.4.200.0330.05316.67
5.4.190.0400.05018.70
5.4.180.0300.06318.75
5.4.170.0300.06718.79
5.4.160.0400.05018.73
5.4.150.0370.05718.81
5.4.140.0430.04316.45
5.4.130.0500.07016.36
5.4.120.0300.09316.22
5.4.110.0370.08316.26
5.4.100.0400.08316.34
5.4.90.0330.05316.30
5.4.80.0230.06316.45
5.4.70.0300.05716.27
5.4.60.0330.06316.44
5.4.50.0530.04316.32
5.4.40.0400.05716.44
5.4.30.0270.06316.36
5.4.20.0200.06716.29
5.4.10.0270.06316.12
5.4.00.0230.06015.80
5.3.290.0270.06314.71
5.3.280.0300.06014.79
5.3.270.0270.06714.73
5.3.260.0300.06314.70
5.3.250.0400.08014.80
5.3.240.0430.08014.65
5.3.230.0270.06314.84
5.3.220.0270.06314.69
5.3.210.0330.06014.64
5.3.200.0300.05714.64
5.3.190.0230.10014.69
5.3.180.0230.07014.60
5.3.170.0370.06014.76
5.3.160.0500.04314.61
5.3.150.0400.06314.80
5.3.140.0370.05314.63
5.3.130.0230.07314.67
5.3.120.0430.05314.61
5.3.110.0430.05014.63
5.3.100.0400.08314.28
5.3.90.0400.05714.02
5.3.80.0500.06714.10
5.3.70.0370.05314.21
5.3.60.0430.08014.15
5.3.50.0330.06314.05
5.3.40.0330.06014.14
5.3.30.0370.06013.97
5.3.20.0370.05313.81
5.3.10.0200.06713.80
5.3.00.0230.06313.66
5.2.170.0300.05311.21
5.2.160.0270.07311.27
5.2.150.0230.08011.29
5.2.140.0370.07311.31
5.2.130.0230.05011.18
5.2.120.0130.05311.18
5.2.110.0070.05711.14
5.2.100.0100.05311.19
5.2.90.0130.05011.23
5.2.80.0070.05711.14
5.2.70.0270.05011.17
5.2.60.0230.04711.17
5.2.50.0230.05711.07
5.2.40.0100.05711.04
5.2.30.0230.04711.09
5.2.20.0230.04311.03
5.2.10.0230.06710.93
5.2.00.0230.07010.80
5.1.60.0230.04310.11
5.1.50.0230.04710.08
5.1.40.0200.04710.14
5.1.30.0200.04710.47
5.1.20.0130.05010.34
5.1.10.0200.03310.16
5.1.00.0170.03310.11
5.0.50.0230.0338.70
5.0.40.0200.0338.52
5.0.30.0200.0438.46
5.0.20.0070.0308.26
5.0.10.0070.0338.30
5.0.00.0100.0438.39
4.4.90.0100.0275.90
4.4.80.0130.0205.86
4.4.70.0070.0235.87
4.4.60.0200.0235.88
4.4.50.0170.0175.88
4.4.40.0170.0335.91
4.4.30.0170.0175.91
4.4.20.0000.0305.96
4.4.10.0070.0236.02
4.4.00.0070.0405.95
4.3.110.0200.0175.85
4.3.100.0130.0305.81
4.3.90.0100.0305.86
4.3.80.0100.0335.77
4.3.70.0070.0235.82
4.3.60.0100.0205.81
4.3.50.0030.0275.82
4.3.40.0100.0305.74
4.3.30.0030.0235.13
4.3.20.0070.0205.13
4.3.10.0030.0235.13
4.3.00.0130.0207.30

preferences:
47.22 ms | 1583 KiB | 5 Q