3v4l.org

run code in 300+ PHP versions simultaneously
<?php function wordsToArr($str) { $words =[]; $ex_str =explode(' ',$str); foreach ($ex_str as $k=>$v) { $words[] =implode(' ',$ex_str); unset($ex_str[$k]); } return $words; } function wordsToArr2($str) { $words = [$str]; while ($pos =strpos ( $str , ' ')) { $str=substr($str,($pos+1)); $words[] =$str; } return $words; } function wordsToArr3($str) { $base = array_reverse(explode(' ', $str)); $words = [$placeholder = array_shift($base)]; foreach ($base as $word) { $words[] = $placeholder = $word . ' ' . $placeholder; } return array_reverse($words); } $sentence = 'The quick brown fox jumps over the lazy dog'; $now = microtime(true); for ($i=0;$i<100;$i++) { wordsToArr($sentence); } $end = microtime(true); echo 'implode '. $i .' times in: ' . number_format($end - $now, 8) . '/sec' . PHP_EOL; $now = microtime(true); for ($i=0;$i<100;$i++) { wordsToArr2($sentence); } $end = microtime(true); echo 'strpos '. $i .' times in: ' . number_format($end - $now, 8) . '/sec' . PHP_EOL; $now = microtime(true); for ($i=0;$i<100;$i++) { wordsToArr3($sentence); } $end = microtime(true); echo 'concat '. $i .' times in: ' . number_format($end - $now, 8) . '/sec' . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 7
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 34
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
2 jumps found. (Code = 44) Position 1 = 67, Position 2 = 61
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 67, Position 2 = 61
Branch analysis from position: 67
Branch analysis from position: 61
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 34
Branch analysis from position: 40
Branch analysis from position: 34
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 7
Branch analysis from position: 13
Branch analysis from position: 7
filename:       /in/j5YMm
function name:  (null)
number of ops:  83
compiled vars:  !0 = $sentence, !1 = $now, !2 = $i, !3 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ASSIGN                                                   !0, 'The+quick+brown+fox+jumps+over+the+lazy+dog'
   35     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !1, $5
   36     5        ASSIGN                                                   !2, 0
          6      > JMP                                                      ->11
   37     7    >   INIT_FCALL                                               'wordstoarr'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0          
   36    10        PRE_INC                                                  !2
         11    >   IS_SMALLER                                               !2, 100
         12      > JMPNZ                                                    ~10, ->7
   39    13    >   INIT_FCALL                                               'microtime'
         14        SEND_VAL                                                 <true>
         15        DO_ICALL                                         $11     
         16        ASSIGN                                                   !3, $11
   40    17        CONCAT                                           ~13     'implode+', !2
         18        CONCAT                                           ~14     ~13, '+times+in%3A+'
         19        INIT_FCALL                                               'number_format'
         20        SUB                                              ~15     !3, !1
         21        SEND_VAL                                                 ~15
         22        SEND_VAL                                                 8
         23        DO_ICALL                                         $16     
         24        CONCAT                                           ~17     ~14, $16
         25        CONCAT                                           ~18     ~17, '%2Fsec'
         26        CONCAT                                           ~19     ~18, '%0A'
         27        ECHO                                                     ~19
   42    28        INIT_FCALL                                               'microtime'
         29        SEND_VAL                                                 <true>
         30        DO_ICALL                                         $20     
         31        ASSIGN                                                   !1, $20
   43    32        ASSIGN                                                   !2, 0
         33      > JMP                                                      ->38
   44    34    >   INIT_FCALL                                               'wordstoarr2'
         35        SEND_VAR                                                 !0
         36        DO_FCALL                                      0          
   43    37        PRE_INC                                                  !2
         38    >   IS_SMALLER                                               !2, 100
         39      > JMPNZ                                                    ~25, ->34
   46    40    >   INIT_FCALL                                               'microtime'
         41        SEND_VAL                                                 <true>
         42        DO_ICALL                                         $26     
         43        ASSIGN                                                   !3, $26
   47    44        CONCAT                                           ~28     'strpos+', !2
         45        CONCAT                                           ~29     ~28, '+times+in%3A+'
         46        INIT_FCALL                                               'number_format'
         47        SUB                                              ~30     !3, !1
         48        SEND_VAL                                                 ~30
         49        SEND_VAL                                                 8
         50        DO_ICALL                                         $31     
         51        CONCAT                                           ~32     ~29, $31
         52        CONCAT                                           ~33     ~32, '%2Fsec'
         53        CONCAT                                           ~34     ~33, '%0A'
         54        ECHO                                                     ~34
   49    55        INIT_FCALL                                               'microtime'
         56        SEND_VAL                                                 <true>
         57        DO_ICALL                                         $35     
         58        ASSIGN                                                   !1, $35
   50    59        ASSIGN                                                   !2, 0
         60      > JMP                                                      ->65
   51    61    >   INIT_FCALL                                               'wordstoarr3'
         62        SEND_VAR                                                 !0
         63        DO_FCALL                                      0          
   50    64        PRE_INC                                                  !2
         65    >   IS_SMALLER                                               !2, 100
         66      > JMPNZ                                                    ~40, ->61
   53    67    >   INIT_FCALL                                               'microtime'
         68        SEND_VAL                                                 <true>
         69        DO_ICALL                                         $41     
         70        ASSIGN                                                   !3, $41
   54    71        CONCAT                                           ~43     'concat+', !2
         72        CONCAT                                           ~44     ~43, '+times+in%3A+'
         73        INIT_FCALL                                               'number_format'
         74        SUB                                              ~45     !3, !1
         75        SEND_VAL                                                 ~45
         76        SEND_VAL                                                 8
         77        DO_ICALL                                         $46     
         78        CONCAT                                           ~47     ~44, $46
         79        CONCAT                                           ~48     ~47, '%2Fsec'
         80        CONCAT                                           ~49     ~48, '%0A'
         81        ECHO                                                     ~49
   55    82      > RETURN                                                   1

Function wordstoarr:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 18
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/j5YMm
function name:  wordsToArr
number of ops:  21
compiled vars:  !0 = $str, !1 = $words, !2 = $ex_str, !3 = $v, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '+'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $6      
          6        ASSIGN                                                   !2, $6
    6     7      > FE_RESET_R                                       $8      !2, ->18
          8    > > FE_FETCH_R                                       ~9      $8, !3, ->18
          9    >   ASSIGN                                                   !4, ~9
    7    10        INIT_FCALL                                               'implode'
         11        SEND_VAL                                                 '+'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $12     
         14        ASSIGN_DIM                                               !1
         15        OP_DATA                                                  $12
    8    16        UNSET_DIM                                                !2, !4
    6    17      > JMP                                                      ->8
         18    >   FE_FREE                                                  $8
   11    19      > RETURN                                                   !1
   12    20*     > RETURN                                                   null

End of function wordstoarr

Function wordstoarr2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 4
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 4
Branch analysis from position: 18
Branch analysis from position: 4
filename:       /in/j5YMm
function name:  wordsToArr2
number of ops:  20
compiled vars:  !0 = $str, !1 = $words, !2 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        INIT_ARRAY                                       ~3      !0
          2        ASSIGN                                                   !1, ~3
   16     3      > JMP                                                      ->12
   17     4    >   INIT_FCALL                                               'substr'
          5        SEND_VAR                                                 !0
          6        ADD                                              ~5      !2, 1
          7        SEND_VAL                                                 ~5
          8        DO_ICALL                                         $6      
          9        ASSIGN                                                   !0, $6
   18    10        ASSIGN_DIM                                               !1
         11        OP_DATA                                                  !0
   16    12    >   INIT_FCALL                                               'strpos'
         13        SEND_VAR                                                 !0
         14        SEND_VAL                                                 '+'
         15        DO_ICALL                                         $9      
         16        ASSIGN                                           ~10     !2, $9
         17      > JMPNZ                                                    ~10, ->4
   21    18    > > RETURN                                                   !1
   22    19*     > RETURN                                                   null

End of function wordstoarr2

Function wordstoarr3:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 23
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 23
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/j5YMm
function name:  wordsToArr3
number of ops:  29
compiled vars:  !0 = $str, !1 = $base, !2 = $words, !3 = $placeholder, !4 = $word
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        INIT_FCALL                                               'array_reverse'
          2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '+'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $5      
          6        SEND_VAR                                                 $5
          7        DO_ICALL                                         $6      
          8        ASSIGN                                                   !1, $6
   26     9        INIT_FCALL                                               'array_shift'
         10        SEND_REF                                                 !1
         11        DO_ICALL                                         $8      
         12        ASSIGN                                           ~9      !3, $8
         13        INIT_ARRAY                                       ~10     ~9
         14        ASSIGN                                                   !2, ~10
   27    15      > FE_RESET_R                                       $12     !1, ->23
         16    > > FE_FETCH_R                                               $12, !4, ->23
   28    17    >   CONCAT                                           ~14     !4, '+'
         18        CONCAT                                           ~15     ~14, !3
         19        ASSIGN                                           ~16     !3, ~15
         20        ASSIGN_DIM                                               !2
         21        OP_DATA                                                  ~16
   27    22      > JMP                                                      ->16
         23    >   FE_FREE                                                  $12
   31    24        INIT_FCALL                                               'array_reverse'
         25        SEND_VAR                                                 !2
         26        DO_ICALL                                         $17     
         27      > RETURN                                                   $17
   32    28*     > RETURN                                                   null

End of function wordstoarr3

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.9 ms | 1037 KiB | 24 Q