3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Workaround for PHP < 5.3.0 */ if(!function_exists('date_diff2')) { class DateInterval1 { public $y; public $m; public $d; public $h; public $i; public $s; public $invert; public $days; public function format($format) { $format = str_replace('%R%y', ($this->invert ? '-' : '+') . $this->y, $format); $format = str_replace('%R%m', ($this->invert ? '-' : '+') . $this->m, $format); $format = str_replace('%R%d', ($this->invert ? '-' : '+') . $this->d, $format); $format = str_replace('%R%h', ($this->invert ? '-' : '+') . $this->h, $format); $format = str_replace('%R%i', ($this->invert ? '-' : '+') . $this->i, $format); $format = str_replace('%R%s', ($this->invert ? '-' : '+') . $this->s, $format); $format = str_replace('%y', $this->y, $format); $format = str_replace('%m', $this->m, $format); $format = str_replace('%d', $this->d, $format); $format = str_replace('%h', $this->h, $format); $format = str_replace('%i', $this->i, $format); $format = str_replace('%s', $this->s, $format); return $format; } } function date_diff2(DateTime $date1, DateTime $date2) { $diff = new DateInterval1(); if($date1 > $date2) { $tmp = $date1; $date1 = $date2; $date2 = $tmp; $diff->invert = 1; } else { $diff->invert = 0; } $diff->y = ((int) $date2->format('Y')) - ((int) $date1->format('Y')); $diff->m = ((int) $date2->format('n')) - ((int) $date1->format('n')); if($diff->m < 0) { $diff->y -= 1; $diff->m = $diff->m + 12; } $diff->d = ((int) $date2->format('j')) - ((int) $date1->format('j')); if($diff->d < 0) { $diff->m -= 1; $diff->d = $diff->d + ((int) $date1->format('t')); } $diff->h = ((int) $date2->format('G')) - ((int) $date1->format('G')); if($diff->h < 0) { $diff->d -= 1; $diff->h = $diff->h + 24; } $diff->i = ((int) $date2->format('i')) - ((int) $date1->format('i')); if($diff->i < 0) { $diff->h -= 1; $diff->i = $diff->i + 60; } $diff->s = ((int) $date2->format('s')) - ((int) $date1->format('s')); if($diff->s < 0) { $diff->i -= 1; $diff->s = $diff->s + 60; } $start_ts = $date1->format('U'); $end_ts = $date2->format('U'); $days = $end_ts - $start_ts; $diff->days = round($days / 86400); if (($diff->h > 0 || $diff->i > 0 || $diff->s > 0)) $diff->days += ((bool) $diff->invert) ? 1 : -1; return $diff; } function formatHour($hours, $minutes) { // format info if ($minutes < 0) { // minutes < 0 // sub hours $hours -= floor(-$minutes / 60) + 1; // make minutes to objective $minutes += (floor(-$minutes / 60) + 1) * 60; } else { // minute > 0 // add hours $hours += floor($minutes / 60); // make minutes to < 60 $minutes -= floor($minutes / 60) * 60; } // make sure minutes patter in mm if ($minutes < 10) { $minutes = "0" . $minutes; } // return pattern hours:minutes return $hours . ':' . $minutes; } } // array(['2014-03-17 16:07:52', '2014-03-17 17:43:09'], '1:35'), $start_time = "2014-03-17 16:07:52"; $end_time = "2014-03-17 17:43:09"; $start_time = new DateTime($start_time); $end_time = new DateTime($end_time); $interval = date_diff2($start_time, $end_time); list($days, $hours, $minutes) = explode(':', $interval->format('%d:%h:%i')); $hours += ($days * 24); print_r(formatHour($hours, $minutes)); echo '<br />'; echo phpversion();

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.4.10.0060.01215.21
7.4.00.0060.01015.49
7.3.130.0110.00715.12
7.3.120.0060.00915.07
7.3.110.0120.00515.15
7.3.100.0080.00515.16
7.3.90.0090.00415.17
7.3.80.0050.00814.84
7.3.70.0070.00715.08
7.3.60.0070.00514.96
7.3.50.0050.00915.06
7.3.40.0040.00815.16
7.3.30.0060.00614.87
7.3.20.0030.00816.86
7.3.10.0050.01216.72
7.3.00.0070.00716.82
7.2.260.0040.01115.44
7.2.250.0070.01015.55
7.2.240.0050.00715.53
7.2.230.0080.00815.46
7.2.220.0090.00515.59
7.2.210.0050.00915.31
7.2.200.0050.00815.39
7.2.190.0050.00815.34
7.2.180.0050.00815.39
7.2.170.0000.01315.40
7.2.160.0000.01215.46
7.2.150.0060.00617.20
7.2.140.0020.00817.15
7.2.130.0070.01017.16
7.2.120.0050.00716.96
7.2.110.0070.00817.13
7.2.100.0070.00817.09
7.2.90.0080.00716.97
7.2.80.0090.00517.18
7.2.70.0110.00317.20
7.2.60.0050.01017.15
7.2.50.0030.01017.10
7.2.40.0120.00317.02
7.2.30.0030.01216.96
7.2.20.0040.00716.99
7.2.10.0060.00516.95
7.2.00.0090.00517.93
7.1.330.0050.00816.01
7.1.320.0070.00515.97
7.1.310.0080.00616.03
7.1.300.0030.00815.91
7.1.290.0030.00815.91
7.1.280.0040.00716.02
7.1.270.0030.01016.05
7.1.260.0050.00915.91
7.1.250.0030.01016.00
7.1.240.0100.00315.96
7.1.230.0060.00615.86
7.1.220.0070.00715.95
7.1.210.0030.00715.82
7.1.200.0060.00915.98
7.1.190.0090.00315.67
7.1.180.0040.00816.02
7.1.170.0070.00716.01
7.1.160.0000.01016.10
7.1.150.0100.01016.10
7.1.140.0030.01016.13
7.1.130.0000.01115.86
7.1.120.0090.00315.99
7.1.110.0040.00816.20
7.1.100.0030.00716.90
7.1.90.0030.00915.96
7.1.80.0040.00815.79
7.1.70.0030.01016.63
7.1.60.0070.01417.62
7.1.50.0090.00816.47
7.1.40.0000.01415.95
7.1.30.0100.00315.85
7.1.20.0030.01015.93
7.1.10.0030.01015.98
7.1.00.0000.04419.16
7.0.330.0070.00715.63
7.0.320.0000.01215.78
7.0.310.0080.00415.64
7.0.300.0070.00315.70
7.0.290.0110.00415.66
7.0.280.0000.00815.56
7.0.270.0030.00615.53
7.0.260.0040.01115.45
7.0.250.0110.00315.70
7.0.240.0000.00815.32
7.0.230.0030.00915.56
7.0.220.0140.00015.56
7.0.210.0060.00615.52
7.0.200.0040.00716.14
7.0.190.0080.00015.35
7.0.180.0070.00715.79
7.0.170.0120.00315.68
7.0.160.0060.00615.68
7.0.150.0060.00315.57
7.0.140.0080.03518.77
7.0.130.0060.00615.39
7.0.120.0070.00715.53
7.0.110.0060.00615.74
7.0.100.0180.03217.68
7.0.90.0120.04117.87
7.0.80.0110.02817.78
7.0.70.0080.03817.86
7.0.60.0030.03617.85
7.0.50.0080.03118.07
7.0.40.0080.04116.89
7.0.30.0150.02516.82
7.0.20.0080.04016.65
7.0.10.0060.04616.78
7.0.00.0100.04116.78
5.6.400.0030.01214.64
5.6.390.0070.01014.90
5.6.380.0000.01214.46
5.6.370.0000.01014.44
5.6.360.0000.01214.63
5.6.350.0030.01014.55
5.6.340.0100.00014.65
5.6.330.0070.00314.62
5.6.320.0040.01114.66
5.6.310.0070.00714.66
5.6.300.0090.00614.80
5.6.290.0090.00614.84
5.6.280.0050.03818.04
5.6.270.0030.00914.51
5.6.260.0070.00314.59
5.6.250.0030.04717.65
5.6.240.0080.04317.75
5.6.230.0080.04217.64
5.6.220.0140.03817.56
5.6.210.0090.03217.63
5.6.200.0120.04417.74
5.6.190.0050.04617.89
5.6.180.0050.03117.92
5.6.170.0060.03817.80
5.6.160.0080.04517.76
5.6.150.0030.03017.81
5.6.140.0080.04217.81
5.6.130.0090.04417.85
5.6.120.0100.04717.80
5.6.110.0060.04017.78
5.6.100.0080.05017.84
5.6.90.0060.03217.83
5.6.80.0040.04717.54
5.6.70.0040.04317.69
5.6.60.0130.03717.57
5.6.50.0100.04017.35
5.6.40.0090.03017.53
5.6.30.0100.04017.59
5.6.20.0050.04217.57
5.6.10.0110.03617.44
5.6.00.0070.04517.48
5.5.380.0100.02817.40
5.5.370.0030.04517.48
5.5.360.0100.03317.55
5.5.350.0080.04617.52
5.5.340.0080.02917.91
5.5.330.0120.03917.69
5.5.320.0060.04117.78
5.5.310.0120.04017.71
5.5.300.0160.03517.76
5.5.290.0070.03117.79
5.5.280.0070.04617.52
5.5.270.0070.02917.79
5.5.260.0070.04617.74
5.5.250.0080.04317.54
5.5.240.0050.04417.34
5.5.230.0130.03617.43
5.5.220.0050.04717.41
5.5.210.0000.04517.40
5.5.200.0100.04317.46
5.5.190.0040.04617.42
5.5.180.0090.04117.46
5.5.170.0060.00914.27
5.5.160.0050.04217.30
5.5.150.0050.04517.27
5.5.140.0100.04217.52
5.5.130.0070.03217.30
5.5.120.0120.02717.38
5.5.110.0070.04417.37
5.5.100.0110.03817.21
5.5.90.0060.03617.29
5.5.80.0080.04317.30
5.5.70.0080.03817.25
5.5.60.0070.04217.31
5.5.50.0100.04217.17
5.5.40.0130.03217.20
5.5.30.0100.04017.42
5.5.20.0080.03917.22
5.5.10.0050.04417.27
5.5.00.0000.04317.31
5.4.450.0090.04015.88
5.4.440.0040.03415.73
5.4.430.0030.02915.83
5.4.420.0050.03015.84
5.4.410.0090.03715.77
5.4.400.0100.03915.67
5.4.390.0070.04015.63
5.4.380.0050.04315.70
5.4.370.0090.04015.63
5.4.360.0080.04215.72
5.4.350.0120.03215.65
5.4.340.0070.03715.67
5.4.330.0030.00712.22
5.4.320.0050.04315.62
5.4.310.0050.04115.57
5.4.300.0180.02815.63
5.4.290.0060.03715.74
5.4.280.0050.04215.71
5.4.270.0030.04615.67
5.4.260.0050.04015.60
5.4.250.0030.02615.65
5.4.240.0050.03315.67
5.4.230.0060.02315.58
5.4.220.0060.02915.65
5.4.210.0080.03915.66
5.4.200.0030.03915.66
5.4.190.0090.03315.70
5.4.180.0090.03615.56
5.4.170.0070.04015.65
5.4.160.0020.04115.67
5.4.150.0030.02715.63
5.4.140.0070.04114.29
5.4.130.0030.04314.34
5.4.120.0060.03714.36
5.4.110.0090.03014.38
5.4.100.0040.03914.27
5.4.90.0080.03814.28
5.4.80.0030.04414.33
5.4.70.0060.03914.33
5.4.60.0030.04214.37
5.4.50.0020.02914.39
5.4.40.0030.03814.35
5.4.30.0050.03714.33
5.4.20.0040.03414.26
5.4.10.0020.02714.41
5.4.00.0060.03714.04
5.3.290.0050.04113.53
5.3.280.0040.04113.49
5.3.270.0030.04513.44
5.3.260.0070.03713.51
5.3.250.0060.03813.49
5.3.240.0080.03813.44
5.3.230.0050.04013.45
5.3.220.0020.04413.48
5.3.210.0030.04013.44
5.3.200.0090.03713.46
5.3.190.0060.03813.47
5.3.180.0050.02313.44
5.3.170.0090.03713.46
5.3.160.0030.03913.46
5.3.150.0050.04013.41
5.3.140.0050.04013.48
5.3.130.0050.04013.47
5.3.120.0050.04013.44
5.3.110.0050.04213.47
5.3.100.0050.03713.16
5.3.90.0030.04113.21
5.3.80.0080.03813.15
5.3.70.0020.04413.21
5.3.60.0080.03613.13
5.3.50.0050.04213.11
5.3.40.0050.04113.11
5.3.30.0020.04313.12
5.3.20.0070.04012.99
5.3.10.0090.03112.99
5.3.00.0070.03813.00

preferences:
46.86 ms | 400 KiB | 5 Q