3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // тест для foreach function foreach_test($range) { // массив $array = range(1, $range); // старт $start = microtime(true); // обработка массива foreach ($array as &$value) { $value /= 2; } // финиш $finish = microtime(true); // время выполнения return round($finish - $start, 5); } // тест для array_walk function array_walk_test($range) { // массив $array = range(1, $range); // старт $start = microtime(true); // обработка array_walk($array, function(&$value){ $value /= 2; }); // финиш $finish = microtime(true); // время выполнения return round($finish - $start, 5); } // тесты $tests = array(1000); // выполнение тестов и результаты foreach ($tests as $range) { $ft = foreach_test($range); $awt = array_walk_test($range); $div = round($awt / $ft, 2); echo "Количество элементов: {$range} <br>"; echo "Время foreach: {$ft}с <br>"; echo "Время array_walk: {$awt}с <br>"; echo "foreach быстрей array_walk в {$div} раз <br><br>"; }
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 4, Position 2 = 36
Branch analysis from position: 4
Jump found. Position 1 = 5, Position 2 = 36
Branch analysis from position: 5
Jump found. Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 36
Jump found. Position 1 = -2
Branch analysis from position: 36
filename:       /in/oZ6sT
function name:  (null)
number of ops:  38
compiled vars:  !0 = $tests, !1 = $range, !2 = $ft, !3 = $awt, !4 = $div
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   4     0  E >   NOP                                                      
  25     1        NOP                                                      
  46     2        ASSIGN                                                   !0, <array>
  49     3      > FE_RESET_R                                       $6      !0, ->36
         4    > > FE_FETCH_R                                               $6, !1, ->36
  50     5    >   INIT_FCALL                                               'foreach_test'
         6        SEND_VAR                                                 !1
         7        DO_FCALL                                      0  $7      
         8        ASSIGN                                                   !2, $7
  51     9        INIT_FCALL                                               'array_walk_test'
        10        SEND_VAR                                                 !1
        11        DO_FCALL                                      0  $9      
        12        ASSIGN                                                   !3, $9
  52    13        INIT_FCALL                                               'round'
        14        DIV                                              ~11     !3, !2
        15        SEND_VAL                                                 ~11
        16        SEND_VAL                                                 2
        17        DO_ICALL                                         $12     
        18        ASSIGN                                                   !4, $12
  54    19        ROPE_INIT                                     3  ~15     '%D0%9A%D0%BE%D0%BB%D0%B8%D1%87%D0%B5%D1%81%D1%82%D0%B2%D0%BE+%D1%8D%D0%BB%D0%B5%D0%BC%D0%B5%D0%BD%D1%82%D0%BE%D0%B2%3A+'
        20        ROPE_ADD                                      1  ~15     ~15, !1
        21        ROPE_END                                      2  ~14     ~15, '+%3Cbr%3E'
        22        ECHO                                                     ~14
  55    23        ROPE_INIT                                     3  ~18     '%D0%92%D1%80%D0%B5%D0%BC%D1%8F+foreach%3A+'
        24        ROPE_ADD                                      1  ~18     ~18, !2
        25        ROPE_END                                      2  ~17     ~18, '%D1%81+%3Cbr%3E'
        26        ECHO                                                     ~17
  56    27        ROPE_INIT                                     3  ~21     '%D0%92%D1%80%D0%B5%D0%BC%D1%8F+array_walk%3A+'
        28        ROPE_ADD                                      1  ~21     ~21, !3
        29        ROPE_END                                      2  ~20     ~21, '%D1%81+%3Cbr%3E'
        30        ECHO                                                     ~20
  57    31        ROPE_INIT                                     3  ~24     'foreach+%D0%B1%D1%8B%D1%81%D1%82%D1%80%D0%B5%D0%B9+array_walk+%D0%B2+'
        32        ROPE_ADD                                      1  ~24     ~24, !4
        33        ROPE_END                                      2  ~23     ~24, '+%D1%80%D0%B0%D0%B7+%3Cbr%3E%3Cbr%3E'
        34        ECHO                                                     ~23
        35      > JMP                                                      ->4
        36    >   FE_FREE                                                  $6
        37      > RETURN                                                   1

Function foreach_test:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
Jump found. Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
Jump found. Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 14
Jump found. Position 1 = -2
Branch analysis from position: 14
filename:       /in/oZ6sT
function name:  foreach_test
number of ops:  26
compiled vars:  !0 = $range, !1 = $array, !2 = $start, !3 = $value, !4 = $finish
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   4     0  E >   RECV                                             !0      
   7     1        INIT_FCALL                                               'range'
         2        SEND_VAL                                                 1
         3        SEND_VAR                                                 !0
         4        DO_ICALL                                         $5      
         5        ASSIGN                                                   !1, $5
  10     6        INIT_FCALL                                               'microtime'
         7        SEND_VAL                                                 <true>
         8        DO_ICALL                                         $7      
         9        ASSIGN                                                   !2, $7
  13    10      > FE_RESET_RW                                      $9      !1, ->14
        11    > > FE_FETCH_RW                                              $9, !3, ->14
  14    12    >   ASSIGN_DIV                                    0          !3, 2
        13      > JMP                                                      ->11
        14    >   FE_FREE                                                  $9
  18    15        INIT_FCALL                                               'microtime'
        16        SEND_VAL                                                 <true>
        17        DO_ICALL                                         $11     
        18        ASSIGN                                                   !4, $11
  21    19        INIT_FCALL                                               'round'
        20        SUB                                              ~13     !4, !2
        21        SEND_VAL                                                 ~13
        22        SEND_VAL                                                 5
        23        DO_ICALL                                         $14     
        24      > RETURN                                                   $14
  22    25*     > RETURN                                                   null

End of function foreach_test

Function %00%7Bclosure%7D%2Fin%2FoZ6sT0x7fe63cda9294:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/oZ6sT
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $value
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  34     0  E >   RECV                                             !0      
  35     1        ASSIGN_DIV                                    0          !0, 2
  36     2      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FoZ6sT0x7fe63cda9294

Function array_walk_test:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/oZ6sT
function name:  array_walk_test
number of ops:  26
compiled vars:  !0 = $range, !1 = $array, !2 = $start, !3 = $finish
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  25     0  E >   RECV                                             !0      
  28     1        INIT_FCALL                                               'range'
         2        SEND_VAL                                                 1
         3        SEND_VAR                                                 !0
         4        DO_ICALL                                         $4      
         5        ASSIGN                                                   !1, $4
  31     6        INIT_FCALL                                               'microtime'
         7        SEND_VAL                                                 <true>
         8        DO_ICALL                                         $6      
         9        ASSIGN                                                   !2, $6
  34    10        INIT_FCALL                                               'array_walk'
        11        SEND_REF                                                 !1
        12        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FoZ6sT0x7fe63cda9294'
  36    13        SEND_VAL                                                 ~8
        14        DO_ICALL                                                 
  39    15        INIT_FCALL                                               'microtime'
        16        SEND_VAL                                                 <true>
        17        DO_ICALL                                         $10     
        18        ASSIGN                                                   !3, $10
  42    19        INIT_FCALL                                               'round'
        20        SUB                                              ~12     !3, !2
        21        SEND_VAL                                                 ~12
        22        SEND_VAL                                                 5
        23        DO_ICALL                                         $13     
        24      > RETURN                                                   $13
  43    25*     > RETURN                                                   null

End of function array_walk_test

Generated using Vulcan Logic Dumper, using php 7.2.0