3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tmp = writeBookmark(17); //debug readBookmark($tmp); //debug // Bookmark Encode Function (one site) function writeBookmark($site) { $site = intval($site); $ts = timeStamp(); // calulates the size of the site id (posible options: 1,2,3,4) $site_id_size = strlen($site); // concatonate site id size, timestamp and site id $decoded_num = $site_id_size . $ts . $site; // Encode timestamp (Base 36) $encoded_num = fromDecimalToBase($decoded_num,36); return $encoded_num; //debug } // Bookmark Decode function function readBookmark($bookmark) { // Decode value $decoded_string = fromBaseToDecimal($bookmark, 36); echo $decoded_string . " "; if(!validateBookmark($decoded_string)) echo "Invalid Bookmark"; else if(is_link_expired($decoded_string) echo "Expired Link"; else { // sturf to link location $site_cnt = substr($decoded_string, 0,1); $site_id = substr($decoded_string, -($site_cnt),$site_cnt); $time_stamp = substr($decoded_string, 1,14); echo "site id cnt ". $site_cnt; echo "\ntime stamp ". $time_stamp; echo "\nsite id " . $site_id; // if valid, redirect to link // else redirect to invalide/expired link page }} /* Helper functions */// build timestamp ssmmhhddmmyyyy function timeStamp() { $ts = date('siHdmY'); return $ts;}// base convert (dec to base36)function fromDecimalToBase($in, $to) { $in = (string) $in; $out = ''; for ($i = strlen($in) - 1; $i >= 0; $i--) { $out = base_convert(bcmod($in, $to), 10, $to) . $out; $in = bcdiv($in, $to); } return preg_replace('/^0+/', '', $out);}// base convet (base36 to dec)function fromBaseToDecimal($in, $from) { $in = (string) $in; $out = ''; for ($i = 0, $l = strlen($in); $i < $l; $i++) { $x = base_convert(substr($in, $i, 1), $from, 10); $out = bcadd(bcmul($out, $from), $x); } return preg_replace('/^0+/', '', $out);}function validateBookmark($bm) { // numeric if(!is_numeric($bm)) { echo "nan"; return false; } // between 19 and 16 digits if(strlen($bm) > 19 || strlen($bm) < 16) { echo "outside range"; return false; } // first digit between 1 and 4 $locLength = substr($bm,0,1); if( $locLength <1 || $locLength >4) { echo "bad loc: ".$locLength; return false; } // if is passes all the tests return true return true;}function is_link_expired($ts) { $hou = substr($ts,5,2); $min = substr($ts,3,2); $sec = substr($ts,1,2); $day = substr($ts,7,2); $mon = substr($ts,9,2); $year = substr($ts,11,2); $bm_time = new DateTime($year."-".$mon."-".$day." ".$hou.":".$min.":".$sec); $current_time = new DateTime(); $difference = date_diff($bm_time,$current_time); }function validateURL($str){ return preg_match('/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i',$str);}function sanitize($str){ if(ini_get('magic_quotes_gpc')) $str = stripslashes($str); $str = strip_tags($str); $str = trim($str); $str = htmlspecialchars($str); $str = mysql_real_escape_string($str); return $str;}

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.3.60.0100.00716.74
8.3.50.0050.01222.93
8.3.40.0130.01018.98
8.3.30.0090.00918.94
8.3.20.0040.00420.22
8.3.10.0150.00023.36
8.3.00.0050.00317.75
8.2.180.0120.00316.63
8.2.170.0150.00022.96
8.2.160.0090.00620.39
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0170.00026.16
8.2.120.0040.00421.04
8.2.110.0000.00920.38
8.2.100.0080.00417.72
8.2.90.0040.00419.11
8.2.80.0000.00817.97
8.2.70.0000.01117.50
8.2.60.0000.00818.04
8.2.50.0080.00018.07
8.2.40.0040.00418.03
8.2.30.0030.00618.07
8.2.20.0080.00017.67
8.2.10.0050.00317.89
8.2.00.0000.00817.57
8.1.280.0060.01025.92
8.1.270.0080.00023.84
8.1.260.0080.00026.35
8.1.250.0000.00728.09
8.1.240.0060.00323.72
8.1.230.0060.00623.89
8.1.220.0040.00417.74
8.1.210.0060.00318.77
8.1.200.0000.00917.13
8.1.190.0000.00817.35
8.1.180.0000.00818.10
8.1.170.0050.00318.51
8.1.160.0040.00421.87
8.1.150.0000.00718.70
8.1.140.0000.00817.39
8.1.130.0000.00717.84
8.1.120.0070.00017.38
8.1.110.0000.00817.46
8.1.100.0000.00717.33
8.1.90.0000.00717.29
8.1.80.0000.00717.30
8.1.70.0070.00017.45
8.1.60.0050.00517.50
8.1.50.0060.00317.55
8.1.40.0030.00517.44
8.1.30.0040.00417.64
8.1.20.0030.00617.73
8.1.10.0060.00317.56
8.1.00.0000.00817.41
8.0.300.0030.00318.77
8.0.290.0070.00016.75
8.0.280.0050.00218.32
8.0.270.0050.00317.08
8.0.260.0000.00717.18
8.0.250.0030.00316.95
8.0.240.0040.00416.94
8.0.230.0040.00416.96
8.0.220.0020.00516.95
8.0.210.0070.00016.95
8.0.200.0040.00417.02
8.0.190.0030.00316.92
8.0.180.0040.00416.94
8.0.170.0040.00416.91
8.0.160.0070.00016.82
8.0.150.0000.00716.75
8.0.140.0040.00416.83
8.0.130.0030.00313.42
8.0.120.0000.00816.92
8.0.110.0000.00716.87
8.0.100.0000.00716.85
8.0.90.0040.00416.86
8.0.80.0080.00716.85
8.0.70.0000.00717.00
8.0.60.0040.00416.90
8.0.50.0040.00416.71
8.0.30.0110.00917.02
8.0.20.0060.01117.40
8.0.10.0000.00717.05
8.0.00.0120.00616.74
7.4.330.0000.00615.05
7.4.320.0000.00616.42
7.4.300.0070.00016.50
7.4.290.0030.00316.59
7.4.280.0000.00716.60
7.4.270.0070.00016.64
7.4.260.0040.00416.49
7.4.250.0020.00516.51
7.4.240.0020.00516.60
7.4.230.0050.00316.26
7.4.220.0100.01616.51
7.4.210.0030.01316.63
7.4.200.0070.00016.36
7.4.160.0090.00616.36
7.4.150.0060.01617.40
7.4.140.0100.00917.86
7.4.130.0120.00516.40
7.4.120.0090.01116.57
7.4.110.0070.01016.37
7.4.100.0100.01016.73
7.4.90.0140.00616.55
7.4.80.0080.00919.39
7.4.70.0130.00716.52
7.4.60.0040.01316.42
7.4.50.0000.00516.52
7.4.40.0140.00416.38
7.4.30.0100.00716.36
7.4.00.0090.00614.83
7.3.330.0080.00013.19
7.3.320.0000.00613.18
7.3.310.0030.00316.14
7.3.300.0060.00016.24
7.3.290.0100.01016.37
7.3.280.0100.00716.37
7.3.270.0110.00617.40
7.3.260.0030.01516.30
7.3.250.0110.00616.43
7.3.240.0150.00316.59
7.3.230.0040.01716.48
7.3.210.0030.01316.44
7.3.200.0030.01319.39
7.3.190.0120.00616.41
7.3.180.0090.00616.24
7.3.170.0080.00816.35
7.3.160.0120.00316.52
7.2.330.0090.01016.39
7.2.320.0090.00916.39
7.2.310.0140.01016.35
7.2.300.0110.01116.66
7.2.290.0060.01016.39
7.2.60.0160.00416.65
7.1.200.0030.00715.35
7.1.100.0060.00917.70
7.1.70.0040.00716.73
7.1.60.0090.00919.40
7.1.50.0070.01316.50
7.1.00.0070.07322.36
7.0.200.0130.00016.59
7.0.140.0070.07322.08
7.0.60.0030.08319.95
7.0.50.0130.07717.95
7.0.40.0000.05320.24
7.0.30.0200.04720.30
7.0.20.0200.03720.16
7.0.10.0300.05320.19
7.0.00.0070.07720.23
5.6.280.0100.06721.08
5.6.210.0070.03720.48
5.6.200.0030.08018.15
5.6.190.0070.09020.57
5.6.180.4130.04320.55
5.6.170.0230.04020.66
5.6.160.0070.04020.39
5.6.150.0100.08018.17
5.6.140.0030.08318.16
5.6.130.0070.07718.18
5.6.120.0070.04021.13
5.6.110.0070.05321.02
5.6.100.0100.05021.12
5.6.90.0070.08321.11
5.6.80.0100.07720.49
5.6.70.0130.03020.38
5.5.350.0300.07720.34
5.5.340.0070.08017.99
5.5.330.0070.04020.57
5.5.320.0400.06720.37
5.5.310.0200.08020.32
5.5.300.0030.04717.99
5.5.290.0000.08318.02
5.5.280.0030.04020.90
5.5.270.0100.08320.77
5.5.260.0100.06320.75
5.5.250.0130.08320.69
5.5.240.2700.04020.16
5.4.450.0870.06719.49
5.4.440.0600.07019.54
5.4.430.0830.05319.54
5.4.420.0730.05719.46
5.4.410.0470.06019.24
5.4.400.0730.05019.04
5.4.390.0900.07319.32
5.4.380.0270.04018.61
5.4.370.0070.05318.43
5.4.360.0030.04718.56
5.4.350.0070.04312.02
5.4.340.0090.04412.02
5.4.320.0070.03512.50
5.4.310.0090.03812.50
5.4.300.0090.03612.50
5.4.290.0060.04112.50
5.4.280.0070.03512.40
5.4.270.0060.03712.40
5.4.260.0090.04112.40
5.4.250.0030.04112.40
5.4.240.0050.03712.40
5.4.230.0040.03912.39
5.4.220.0070.03612.39
5.4.210.0160.04812.39
5.4.200.0090.04512.39
5.4.190.0070.03712.39
5.4.180.0070.03712.39
5.4.170.0080.03612.40
5.4.160.0080.03612.39
5.4.150.0080.03512.39
5.4.140.0080.03812.07
5.4.130.0070.03412.06
5.4.120.0070.03512.02
5.4.110.0050.03812.01
5.4.100.0030.03912.01
5.4.90.0070.03712.01
5.4.80.0110.03912.01
5.4.70.0040.03712.01
5.4.60.0050.03612.01
5.4.50.0080.03312.01
5.4.40.0040.03712.00
5.4.30.0060.03711.99
5.4.20.0120.03012.00
5.4.10.0070.03311.99
5.4.00.0110.03111.48
5.3.290.0030.04212.80
5.3.280.0070.03612.71
5.3.270.0050.03912.72
5.3.260.0050.03912.72
5.3.250.0070.03512.72
5.3.240.0090.03412.72
5.3.230.0080.03612.70
5.3.220.0060.03612.68
5.3.210.0060.03912.68
5.3.200.0050.04012.68
5.3.190.0070.03912.68
5.3.180.0070.03712.67
5.3.170.0060.03712.67
5.3.160.0060.03812.67
5.3.150.0080.03712.67
5.3.140.0060.03812.66
5.3.130.0050.04012.66
5.3.120.0060.03912.66
5.3.110.0070.03912.66
5.3.100.0080.03612.12
5.3.90.0060.03612.12
5.3.80.0060.03612.10
5.3.70.0080.03412.09
5.3.60.0030.03912.08
5.3.50.0060.03612.02
5.3.40.0050.03612.02
5.3.30.0080.03311.98
5.3.20.0050.03611.76
5.3.10.0060.03511.73
5.3.00.0050.03711.72
5.2.170.0080.0289.23
5.2.160.0010.0349.23
5.2.150.0050.0309.22
5.2.140.0040.0319.22
5.2.130.0030.0319.18
5.2.120.0040.0299.18
5.2.110.0060.0289.19
5.2.100.0030.0319.18
5.2.90.0090.0259.18
5.2.80.0070.0289.18
5.2.70.0060.0299.18
5.2.60.0030.0329.13
5.2.50.0040.0319.10
5.2.40.0080.0279.08
5.2.30.0070.0359.05
5.2.20.0040.0299.04
5.2.10.0030.0298.95
5.2.00.0010.0328.81
5.1.60.0060.0218.10
5.1.50.0040.0248.09
5.1.40.0030.0258.07
5.1.30.0040.0268.41
5.1.20.0030.0278.44
5.1.10.0040.0258.17
5.1.00.0030.0268.17
5.0.50.0020.0226.64
5.0.40.0060.0166.50
5.0.30.0050.0326.32
5.0.20.0010.0216.28
5.0.10.0020.0256.26
5.0.00.0050.0296.26
4.4.90.0020.0164.78
4.4.80.0040.0144.76
4.4.70.0020.0164.75
4.4.60.0050.0144.75
4.4.50.0030.0164.77
4.4.40.0030.0264.70
4.4.30.0020.0164.76
4.4.20.0030.0154.85
4.4.10.0030.0154.85
4.4.00.0030.0254.76
4.3.110.0020.0174.67
4.3.100.0020.0164.66
4.3.90.0030.0144.64
4.3.80.0030.0244.59
4.3.70.0050.0124.63
4.3.60.0020.0154.63
4.3.50.0010.0174.63
4.3.40.0010.0264.53
4.3.30.0000.0183.30
4.3.20.0030.0173.28
4.3.10.0020.0163.24
4.3.00.0030.0207.07

preferences:
41.58 ms | 401 KiB | 5 Q