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 = (int) (pow(2, $bits) - 1); if ($mask < 0) { // Hack since PHP will upcast 2^63-1 into a negative number $mask = PHP_INT_MAX; } do { $rand = hexdec(bin2hex(substr($this->bytes(8), 0, $bytes))); $result = $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); echo('state changed'); return substr($hash, self::STATE_SIZE); } } $prng = new PseudoRandomSequence("test"); $prng->int(0,99)

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)
5.6.80.0070.08320.37
5.5.240.0000.06720.17
5.4.400.0300.05718.89
5.4.390.0230.06018.63
5.4.380.0330.05018.48
5.4.370.0270.06318.77
5.4.360.0330.05018.57
5.4.350.0270.06018.77
5.4.340.0330.05718.61
5.4.320.0230.06318.65
5.4.310.0330.05718.76
5.4.300.0330.05718.59
5.4.290.0470.05018.79
5.4.280.0300.05318.74
5.4.270.0370.06018.74
5.4.260.0300.05018.77
5.4.250.0270.06018.76
5.4.240.0500.05718.52
5.4.230.0400.04718.76
5.4.220.0300.05718.82
5.4.210.0300.06018.59
5.4.200.0300.05016.58
5.4.190.0300.05018.46
5.4.180.0370.04718.77
5.4.170.0370.04718.73
5.4.160.0300.05018.56
5.4.150.0230.05718.52
5.4.140.0230.05716.17
5.4.130.0270.05016.29
5.4.120.0330.05016.21
5.4.110.0230.05716.21
5.4.100.0330.04716.35
5.4.90.0400.04716.34
5.4.80.0300.06316.42
5.4.70.0370.04716.27
5.4.60.0300.04716.18
5.4.50.0330.04716.23
5.4.40.0270.05316.20
5.4.30.0200.05716.29
5.4.20.0270.05716.19
5.4.10.0330.05316.29
5.4.00.0270.05015.91
5.3.290.0370.04714.85
5.3.280.0370.04314.82
5.3.270.0270.05714.67
5.3.260.0330.06314.67
5.3.250.0270.07314.66
5.3.240.0430.04714.84
5.3.230.0430.05014.64
5.3.220.0330.04714.56
5.3.210.0370.04714.80
5.3.200.0300.05714.60
5.3.190.0370.04714.64
5.3.180.0200.07314.62
5.3.170.0400.04014.57
5.3.160.0200.05714.57
5.3.150.0300.05014.60
5.3.140.0400.04714.70
5.3.130.0330.05714.62
5.3.120.0570.06014.79
5.3.110.0400.07714.63
5.3.100.0470.05314.18
5.3.90.0370.07314.09
5.3.80.0300.07714.24
5.3.70.0430.05014.14
5.3.60.0200.05314.02
5.3.50.0330.06013.96
5.3.40.0230.08014.17
5.3.30.0170.07014.13
5.3.20.0230.05013.91
5.3.10.0230.05313.65
5.3.00.0300.06313.71
5.2.170.0430.04011.28
5.2.160.0370.03711.14
5.2.150.0330.04311.23
5.2.140.0330.05711.26
5.2.130.0300.05711.20
5.2.120.0370.04711.22
5.2.110.0300.05711.15
5.2.100.0530.04311.36
5.2.90.0300.05711.17
5.2.80.0130.07011.18
5.2.70.0270.04011.32
5.2.60.0370.04311.10
5.2.50.0330.05011.02
5.2.40.0300.04011.12
5.2.30.0270.04711.12
5.2.20.0230.03711.00
5.2.10.0330.04311.08
5.2.00.0430.05010.78
5.1.60.0430.04010.22
5.1.50.0400.04010.01
5.1.40.0270.05310.13
5.1.30.0270.04010.53
5.1.20.0270.04010.41
5.1.10.0200.04010.21
5.1.00.0300.03710.21
5.0.50.0300.0278.70
5.0.40.0200.0338.52
5.0.30.0200.0478.23
5.0.20.0170.0338.22
5.0.10.0300.0238.33
5.0.00.0030.0608.30
4.4.90.0170.0305.87
4.4.80.0200.0235.95
4.4.70.0170.0275.98
4.4.60.0230.0305.88
4.4.50.0070.0275.91
4.4.40.0100.0375.88
4.4.30.0230.0205.88
4.4.20.0070.0275.93
4.4.10.0030.0335.98
4.4.00.0170.0435.91
4.3.110.0170.0205.82
4.3.100.0230.0205.81
4.3.90.0130.0175.80
4.3.80.0130.0305.91
4.3.70.0000.0305.82
4.3.60.0130.0175.79
4.3.50.0070.0235.91
4.3.40.0100.0335.83
4.3.30.0100.0205.09
4.3.20.0000.0275.09
4.3.10.0070.0305.09
4.3.00.0070.0207.30

preferences:
143.17 ms | 1394 KiB | 7 Q