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; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 13
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 47
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 47
Branch analysis from position: 53
Branch analysis from position: 47
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 13
Branch analysis from position: 19
Branch analysis from position: 13
filename:       /in/vmTBD
function name:  (null)
number of ops:  71
compiled vars:  !0 = $iterations, !1 = $string, !2 = $benchmark_start, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 5000
    5     1        ASSIGN                                                   !1, 'HD+Alcoa+Earnings+Soar%3B+Outlook+Stays+Upbeat+%0ABY+By+James+R.+Hagerty+and+Matthew+Day+%0APD+12+July+2011%0ALP+%0A%0AAlcoa+Inc.%27s+profit+more+than+doubled+in+the+second+quarter.%0AThe+giant+aluminum+producer+managed+to+meet+analysts%27+forecasts.%0A%0AHowever%2C+profits+wereless+than+expected%0A%0ATD%0ALicence+this+article+via+our+website%3A%0A%0Ahttp%3A%2F%2Fexample.com'
   23     2        ECHO                                                     '-----%0A'
   24     3        INIT_FCALL                                               'strtoupper'
          4        SEND_VAL                                                 'Sweetie+Belle%27s+solution+%28uses+regexp%29%3A%09%09'
          5        DO_ICALL                                         $6      
          6        ECHO                                                     $6
   25     7        INIT_FCALL                                               'microtime'
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $7      
         10        ASSIGN                                                   !2, $7
   26    11        ASSIGN                                                   !3, 0
         12      > JMP                                                      ->17
         13    >   INIT_FCALL_BY_NAME                                       'sb_headerSplit'
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0          
         16        PRE_INC                                                  !3
         17    >   IS_SMALLER                                               !3, !0
         18      > JMPNZ                                                    ~12, ->13
   27    19    >   INIT_FCALL                                               'round'
         20        INIT_FCALL                                               'microtime'
         21        SEND_VAL                                                 <true>
         22        DO_ICALL                                         $13     
         23        SUB                                              ~14     $13, !2
         24        SEND_VAL                                                 ~14
         25        SEND_VAL                                                 3
         26        DO_ICALL                                         $15     
         27        CONCAT                                           ~16     $15, '+seconds%0A'
         28        ECHO                                                     ~16
   28    29        INIT_FCALL                                               'var_dump'
         30        INIT_FCALL_BY_NAME                                       'sb_headerSplit'
         31        SEND_VAR_EX                                              !1
         32        DO_FCALL                                      0  $17     
         33        SEND_VAR                                                 $17
         34        DO_ICALL                                                 
   29    35        ECHO                                                     '%0A'
   32    36        ECHO                                                     '-----%0A'
   33    37        INIT_FCALL                                               'strtoupper'
         38        SEND_VAL                                                 'Hek2mgl%27s+solution+%28uses+regexp%29%3A%09%09'
         39        DO_ICALL                                         $19     
         40        ECHO                                                     $19
   34    41        INIT_FCALL                                               'microtime'
         42        SEND_VAL                                                 <true>
         43        DO_ICALL                                         $20     
         44        ASSIGN                                                   !2, $20
   35    45        ASSIGN                                                   !3, 0
         46      > JMP                                                      ->51
         47    >   INIT_FCALL_BY_NAME                                       'answer_1'
         48        SEND_VAR_EX                                              !1
         49        DO_FCALL                                      0          
         50        PRE_INC                                                  !3
         51    >   IS_SMALLER                                               !3, !0
         52      > JMPNZ                                                    ~25, ->47
   36    53    >   INIT_FCALL                                               'round'
         54        INIT_FCALL                                               'microtime'
         55        SEND_VAL                                                 <true>
         56        DO_ICALL                                         $26     
         57        SUB                                              ~27     $26, !2
         58        SEND_VAL                                                 ~27
         59        SEND_VAL                                                 3
         60        DO_ICALL                                         $28     
         61        CONCAT                                           ~29     $28, '+seconds%0A'
         62        ECHO                                                     ~29
   37    63        INIT_FCALL                                               'var_dump'
         64        INIT_FCALL_BY_NAME                                       'answer_1'
         65        SEND_VAR_EX                                              !1
         66        DO_FCALL                                      0  $30     
         67        SEND_VAR                                                 $30
         68        DO_ICALL                                                 
   38    69        ECHO                                                     '%0A'
   62    70      > RETURN                                                   1

Function sb_headersplit:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 30
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 30
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/vmTBD
function name:  sb_headerSplit
number of ops:  33
compiled vars:  !0 = $input, !1 = $matches, !2 = $split, !3 = $result, !4 = $value, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   43     1        INIT_FCALL                                               'preg_match_all'
          2        SEND_VAL                                                 '%2F%5E%5BA-Z%5D%7B2%7D%2Fm'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
   44     6        INIT_FCALL                                               'preg_split'
          7        SEND_VAL                                                 '%2F%5E%5BA-Z%5D%7B2%7D%2Fm'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 null
         10        SEND_VAL                                                 1
         11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !2, $7
   45    13        ASSIGN                                                   !3, <array>
   46    14        FETCH_DIM_R                                      ~10     !1, 0
         15      > FE_RESET_R                                       $11     ~10, ->30
         16    > > FE_FETCH_R                                       ~12     $11, !4, ->30
         17    >   ASSIGN                                                   !5, ~12
         18        INIT_FCALL                                               'preg_replace'
         19        SEND_VAL                                                 '%2F%5B%0A%0D%5D%2F'
         20        SEND_VAL                                                 '+'
         21        INIT_FCALL                                               'trim'
         22        FETCH_DIM_R                                      ~15     !2, !5
         23        SEND_VAL                                                 ~15
         24        DO_ICALL                                         $16     
         25        SEND_VAR                                                 $16
         26        DO_ICALL                                         $17     
         27        ASSIGN_DIM                                               !3, !4
         28        OP_DATA                                                  $17
         29      > JMP                                                      ->16
         30    >   FE_FREE                                                  $11
   47    31      > RETURN                                                   !3
   48    32*     > RETURN                                                   null

End of function sb_headersplit

Function answer_1:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 24
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/vmTBD
function name:  answer_1
number of ops:  27
compiled vars:  !0 = $input, !1 = $record, !2 = $line, !3 = $matches, !4 = $currentKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   51     1        ASSIGN                                                   !1, <array>
   53     2      > FE_RESET_R                                       $6      !0, ->24
          3    > > FE_FETCH_R                                               $6, !2, ->24
   54     4    >   INIT_FCALL                                               'preg_match'
          5        SEND_VAL                                                 '%7E%5E%28HD%7CBY%7CPD%7CLP%7CTD%29+%3F%28.%2A%29%3F%24%7E'
          6        SEND_VAR                                                 !2
          7        SEND_REF                                                 !3
          8        DO_ICALL                                         $7      
          9      > JMPZ                                                     $7, ->16
   55    10    >   FETCH_DIM_R                                      ~8      !3, 1
         11        ASSIGN                                                   !4, ~8
   56    12        FETCH_DIM_R                                      ~11     !3, 2
         13        ASSIGN_DIM                                               !1, !4
         14        OP_DATA                                                  ~11
         15      > JMP                                                      ->23
   58    16    >   INIT_FCALL                                               'str_replace'
         17        SEND_VAL                                                 '%0A'
         18        SEND_VAL                                                 '+'
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                         $13     
         21        ASSIGN_DIM_OP                .=               8          !1, !4
         22        OP_DATA                                                  $13
   53    23    > > JMP                                                      ->3
         24    >   FE_FREE                                                  $6
   61    25      > RETURN                                                   !1
   62    26*     > RETURN                                                   null

End of function answer_1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.61 ms | 1413 KiB | 33 Q