3v4l.org

run code in 300+ PHP versions simultaneously
<?php $iterations = 5000; $string = "HD Alcoa Earnings Soar; Outlook Stays Upbeat BY By James R. Hagerty and Matthew Day PD 12 July 2011 LP Alcoa Inc.'s profit more than doubled in the second quarter. The giant aluminum producer managed to meet analysts' forecasts. However, profits wereless than expected TD Licence this article via our website: http://example.com"; ## OUTPUT FORMAT & BENCHMARK CODE # SWEETIE BELLE echo "-----\n"; echo strtoupper("Sweetie Belle's solution (uses regexp):\t\t"); $benchmark_start = microtime(true); for($i=0;$i<$iterations;$i++) sb_headerSplit($string); echo round(microtime(true) - $benchmark_start, 3) . " seconds\n"; var_dump(sb_headerSplit($string)); echo "\n"; # HEK2MGL echo "-----\n"; echo strtoupper("Hek2mgl's solution (uses regexp):\t\t"); $benchmark_start = microtime(true); for($i=0;$i<$iterations;$i++) answer_1($string); echo round(microtime(true) - $benchmark_start, 3) . " seconds\n"; var_dump(answer_1($string)); echo "\n"; ## FUNCTIONS BELOW, DO NOT EDIT function sb_headerSplit($input) { preg_match_all("/^[A-Z]{2}/m",$input,$matches); $split = preg_split("/^[A-Z]{2}/m",$input,null,PREG_SPLIT_NO_EMPTY); $result = array(); foreach($matches[0] as $key => $value) $result[$value] = preg_replace("/[\n\r]/"," ",trim($split[$key])); return $result; } function answer_1($input) { $record = array(); //foreach(file('input.txt') as $line) { foreach($input AS $line) { if(preg_match('~^(HD|BY|PD|LP|TD) ?(.*)?$~', $line, $matches)) { $currentKey = $matches[1]; $record[$currentKey] = $matches[2]; } else { $record[$currentKey] .= str_replace("\n", ' ', $line); } } return $record; }

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.0060.02516.98
7.3.00.0060.02516.98
7.2.130.0150.01816.88
7.2.120.0040.02617.02
7.2.110.0060.02616.86
7.2.100.0040.03217.14
7.2.90.0070.03716.95
7.2.80.0070.03916.70
7.2.70.0030.02317.02
7.2.60.0090.02517.29
7.2.50.0100.02317.14
7.2.40.0060.03017.18
7.2.30.0060.03017.16
7.2.20.0100.02217.09
7.2.10.0110.02117.12
7.2.00.0030.03018.23
7.1.250.0030.03616.02
7.1.70.0040.03617.20
7.1.60.0160.04219.29
7.1.50.0130.04417.33
7.1.00.0030.10722.38
7.0.200.0030.02017.00
7.0.140.0030.09722.00
7.0.100.0070.09019.98
7.0.90.0070.11020.00
7.0.80.0100.09020.21
7.0.70.0100.11020.02
7.0.60.0100.07019.93
7.0.50.0570.09320.41
7.0.40.0100.10720.07
7.0.30.0130.09020.12
7.0.20.0070.11720.12
7.0.10.0130.09720.08
7.0.00.0130.10019.96
5.6.280.0000.18321.08
5.6.250.0130.15320.64
5.6.240.0100.16020.70
5.6.230.0100.15720.64
5.6.220.0100.15320.69
5.6.210.0200.15020.47
5.6.200.0130.13020.95
5.6.190.0030.18321.09
5.6.180.0130.17721.02
5.6.170.0070.14021.15
5.6.160.0030.15721.06
5.6.150.0130.15321.13
5.6.140.0030.17021.04
5.6.130.0100.15720.97
5.6.120.0070.14321.02
5.6.110.0100.16021.05
5.6.100.0030.15020.96
5.6.90.0030.13321.02
5.6.80.0130.14020.42
5.6.70.0030.19020.50
5.6.60.0130.15720.49
5.6.50.0070.16720.32
5.6.40.0030.18320.44
5.6.30.0130.16020.43
5.6.20.0030.12020.38
5.6.10.0200.14720.41
5.6.00.0100.16320.36
5.5.380.0100.16720.61
5.5.370.0030.13020.43
5.5.360.0030.17720.36
5.5.350.0100.16020.36
5.5.340.0100.15320.79
5.5.330.0100.15020.94
5.5.320.0170.13720.92
5.5.310.0030.11320.88
5.5.300.0130.16720.80
5.5.290.0000.17320.90
5.5.280.0230.16320.77
5.5.270.0030.18720.89
5.5.260.0070.15020.89
5.5.250.0070.15020.59
5.5.240.0100.16720.21
5.5.230.0100.15720.08
5.5.220.0030.16720.27
5.5.210.0130.13320.22
5.5.200.0100.14720.27
5.5.190.0130.13320.25
5.5.180.0130.16319.98
5.5.160.0030.16720.20
5.5.150.0100.15720.21
5.5.140.0030.15720.26
5.5.130.0200.16020.09
5.5.120.0200.16019.98
5.5.110.0170.15720.12
5.5.100.0130.14320.13
5.5.90.0030.15719.95
5.5.80.0030.15720.02
5.5.70.0000.15020.18
5.5.60.0170.14720.18
5.5.50.0030.14720.10
5.5.40.0030.17320.08
5.5.30.0100.17320.16
5.5.20.0030.15719.97
5.5.10.0030.10720.04
5.5.00.0100.17020.06
5.4.450.0000.12019.27
5.4.440.0200.13719.33
5.4.430.0130.17019.45
5.4.420.0100.14719.26
5.4.410.0070.16719.24
5.4.400.0100.14019.17
5.4.390.0130.14719.13
5.4.380.0300.09718.98
5.4.370.0130.14718.90
5.4.360.0100.16719.05
5.4.350.0130.14318.97
5.4.340.0200.15018.98
5.4.320.0070.10318.90
5.4.310.0100.15319.00
5.4.300.0030.14019.00
5.4.290.0070.15018.96
5.4.280.0100.14319.11
5.4.270.0070.14318.89
5.4.260.0070.16319.05
5.4.250.0170.14718.96
5.4.240.0130.12719.04
5.4.230.0100.14319.11
5.4.220.0100.14318.85
5.4.210.0100.10318.86
5.4.200.0130.13018.96
5.4.190.0070.15019.10
5.4.180.0030.10719.15
5.4.170.0030.15018.95
5.4.160.0030.13319.02
5.4.150.0030.17719.02
5.4.140.0000.11716.35
5.4.130.0070.15016.32
5.4.120.0100.13716.36
5.4.110.0130.15016.53
5.4.100.0100.12316.48
5.4.90.0130.15016.32
5.4.80.0030.15716.48
5.4.70.0070.17016.31
5.4.60.0130.14316.35
5.4.50.0070.22016.38
5.4.40.0130.16016.25
5.4.30.0070.16316.30
5.4.20.0070.15316.30
5.4.10.0070.15716.29
5.4.00.0000.10315.75
5.3.290.0100.16014.48
5.3.280.0070.14314.49
5.3.270.0100.12714.50
5.3.260.0000.11014.60
5.3.250.0070.18714.49
5.3.240.0100.13714.46
5.3.230.0030.15314.55
5.3.220.0100.12714.46
5.3.210.0070.10714.53
5.3.200.0070.11314.51
5.3.190.0030.12314.43
5.3.180.0100.15014.40
5.3.170.0130.16714.45
5.3.160.0070.17014.41
5.3.150.0100.15014.42
5.3.140.0030.16014.45
5.3.130.0030.12714.51
5.3.120.0070.15314.54
5.3.110.0070.16314.42
5.3.100.0070.18014.19
5.3.90.0000.18314.19
5.3.80.0000.17314.19
5.3.70.0070.11314.19
5.3.60.0100.16714.19
5.3.50.0130.13014.19
5.3.40.0030.14314.19
5.3.30.0070.15314.19
5.3.20.0130.16314.19
5.3.10.0130.13014.19
5.3.00.0100.15314.19
5.2.170.0070.14714.19
5.2.160.0000.15314.19
5.2.150.0070.16014.19
5.2.140.0070.13314.19
5.2.130.0000.14014.19
5.2.120.0030.16714.19
5.2.110.0100.12014.19
5.2.100.0070.12314.19
5.2.90.0100.15014.19
5.2.80.0100.13714.19
5.2.70.0000.16314.19
5.2.60.0070.13314.19
5.2.50.0100.16314.19
5.2.40.0130.15014.19
5.2.30.0170.12314.19
5.2.20.0100.12314.19
5.2.10.0100.14314.19
5.2.00.0070.15714.19
5.1.60.0100.13714.19
5.1.50.0000.10314.19
5.1.40.0070.14314.19
5.1.30.0070.09314.19
5.1.20.0130.07714.19
5.1.10.0030.12014.19
5.1.00.0070.10014.19
5.0.50.0070.15714.19
5.0.40.0000.14314.19
5.0.30.0030.11714.19
5.0.20.0000.10314.19
5.0.10.0070.14314.19
5.0.00.0030.16014.19
4.4.90.0000.13014.19
4.4.80.0030.11314.19
4.4.70.0000.16014.19
4.4.60.0200.09314.19
4.4.50.0030.14314.19
4.4.40.0000.11714.19
4.4.30.0000.15714.19
4.4.20.0000.10014.19
4.4.10.0000.15714.19
4.4.00.0100.10714.19
4.3.110.0000.15314.19
4.3.100.0000.15714.19
4.3.90.0000.15314.19
4.3.80.0070.13014.19
4.3.70.0070.10314.19
4.3.60.0030.14714.19
4.3.50.0030.14014.19
4.3.40.0070.14314.19
4.3.30.0000.16314.19
4.3.20.0070.12714.19
4.3.10.0030.15014.19
4.3.00.0000.15314.19

preferences:
37.82 ms | 401 KiB | 5 Q