3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL & ~E_NOTICE); ini_set('display_errors', '1'); define('S', 15000); // list Size define('N', 10); // Number of iterations (for benchmark accuracy) // Comment the lines above and uncomment the lines below to pass the parameters in the command line //define('S', (int)$argv[1]); //define('N', (int)$argv[2]); printf("Generating %d elements... ", S); $tsStart = microtime(TRUE); $array = []; for ($i = 0; $i < S; $i ++) { $array[] = [ 'a' => rand(0, 100), 'f' => 0, 'f' => 0, 'l' => 61.60 ]; } printf("Done. Time: %f seconds.\n", microtime(TRUE) - $tsStart); $time = 0; for ($l = 0; $l < N; $l ++) { $ts = microtime(TRUE); $min = min(array_filter(array_column($array, 'a'))); $time += microtime(TRUE) - $ts; } printf("array_filter(): %9.2f seconds/%d iterations. %f seconds/iteration.\n", $time, N, $time/N); $time = 0; for ($l = 0; $l < N; $l ++) { $ts = microtime(TRUE); $min = null; foreach ($array as $val) { if ($min === null || ($val['a'] && $val['a'] < $min)) { $min = $val['a']; } } $time += microtime(TRUE) - $ts; } printf("foreach : %9.2f seconds/%d iterations. %f seconds/iteration.\n", $time, N, $time/N); $time = 0; for ($l = 0; $l < N; $l ++) { $ts = microtime(TRUE); $min = array_reduce($array, function ($min, $val) { return $min === null || ($val['a'] && $val['a'] < $min) ? $val['a'] : $min; }); $time += microtime(TRUE) - $ts; } printf("reduce @deceze: %9.2f seconds/%d iterations. %f seconds/iteration.\n", $time, N, $time/N); $time = 0; for ($l = 0; $l < N; $l ++) { $ts = microtime(TRUE); $min = array_reduce( $array, function($acc, array $item) { return min($acc, $item['a'] ?: INF); }, INF ); $time += microtime(TRUE) - $ts; } printf("reduce @axiac : %9.2f seconds/%d iterations. %f seconds/iteration.\n", $time, N, $time/N);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 27
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 52
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 114
Branch analysis from position: 114
2 jumps found. (Code = 44) Position 1 = 117, Position 2 = 88
Branch analysis from position: 117
1 jumps found. (Code = 42) Position 1 = 145
Branch analysis from position: 145
2 jumps found. (Code = 44) Position 1 = 148, Position 2 = 129
Branch analysis from position: 148
1 jumps found. (Code = 42) Position 1 = 177
Branch analysis from position: 177
2 jumps found. (Code = 44) Position 1 = 180, Position 2 = 160
Branch analysis from position: 180
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 160
2 jumps found. (Code = 44) Position 1 = 180, Position 2 = 160
Branch analysis from position: 180
Branch analysis from position: 160
Branch analysis from position: 129
2 jumps found. (Code = 44) Position 1 = 148, Position 2 = 129
Branch analysis from position: 148
Branch analysis from position: 129
Branch analysis from position: 88
2 jumps found. (Code = 77) Position 1 = 94, Position 2 = 107
Branch analysis from position: 94
2 jumps found. (Code = 78) Position 1 = 95, Position 2 = 107
Branch analysis from position: 95
2 jumps found. (Code = 47) Position 1 = 97, Position 2 = 103
Branch analysis from position: 97
2 jumps found. (Code = 46) Position 1 = 99, Position 2 = 102
Branch analysis from position: 99
2 jumps found. (Code = 43) Position 1 = 104, Position 2 = 106
Branch analysis from position: 104
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 106
Branch analysis from position: 102
Branch analysis from position: 103
Branch analysis from position: 107
2 jumps found. (Code = 44) Position 1 = 117, Position 2 = 88
Branch analysis from position: 117
Branch analysis from position: 88
Branch analysis from position: 107
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 52
Branch analysis from position: 76
Branch analysis from position: 52
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 27
Branch analysis from position: 41
Branch analysis from position: 27
filename:       /in/1CEqE
function name:  (null)
number of ops:  190
compiled vars:  !0 = $tsStart, !1 = $array, !2 = $i, !3 = $time, !4 = $l, !5 = $ts, !6 = $min, !7 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 32759
          2        DO_ICALL                                                 
    3     3        INIT_FCALL                                               'ini_set'
          4        SEND_VAL                                                 'display_errors'
          5        SEND_VAL                                                 '1'
          6        DO_ICALL                                                 
    6     7        INIT_FCALL                                               'define'
          8        SEND_VAL                                                 'S'
          9        SEND_VAL                                                 15000
         10        DO_ICALL                                                 
    7    11        INIT_FCALL                                               'define'
         12        SEND_VAL                                                 'N'
         13        SEND_VAL                                                 10
         14        DO_ICALL                                                 
   13    15        INIT_FCALL                                               'printf'
         16        SEND_VAL                                                 'Generating+%25d+elements...+'
         17        FETCH_CONSTANT                                   ~12     'S'
         18        SEND_VAL                                                 ~12
         19        DO_ICALL                                                 
   14    20        INIT_FCALL                                               'microtime'
         21        SEND_VAL                                                 <true>
         22        DO_ICALL                                         $14     
         23        ASSIGN                                                   !0, $14
   15    24        ASSIGN                                                   !1, <array>
   16    25        ASSIGN                                                   !2, 0
         26      > JMP                                                      ->38
   18    27    >   INIT_FCALL                                               'rand'
         28        SEND_VAL                                                 0
         29        SEND_VAL                                                 100
         30        DO_ICALL                                         $19     
         31        INIT_ARRAY                                       ~20     $19, 'a'
   19    32        ADD_ARRAY_ELEMENT                                ~20     0, 'f'
   20    33        ADD_ARRAY_ELEMENT                                ~20     0, 'f'
   21    34        ADD_ARRAY_ELEMENT                                ~20     61.6, 'l'
   17    35        ASSIGN_DIM                                               !1
   21    36        OP_DATA                                                  ~20
   16    37        PRE_INC                                                  !2
         38    >   FETCH_CONSTANT                                   ~22     'S'
         39        IS_SMALLER                                               !2, ~22
         40      > JMPNZ                                                    ~23, ->27
   24    41    >   INIT_FCALL                                               'printf'
         42        SEND_VAL                                                 'Done.+Time%3A+%25f+seconds.%0A'
         43        INIT_FCALL                                               'microtime'
         44        SEND_VAL                                                 <true>
         45        DO_ICALL                                         $24     
         46        SUB                                              ~25     $24, !0
         47        SEND_VAL                                                 ~25
         48        DO_ICALL                                                 
   28    49        ASSIGN                                                   !3, 0
   29    50        ASSIGN                                                   !4, 0
         51      > JMP                                                      ->73
   30    52    >   INIT_FCALL                                               'microtime'
         53        SEND_VAL                                                 <true>
         54        DO_ICALL                                         $29     
         55        ASSIGN                                                   !5, $29
   31    56        INIT_FCALL                                               'min'
         57        INIT_FCALL                                               'array_filter'
         58        INIT_FCALL                                               'array_column'
         59        SEND_VAR                                                 !1
         60        SEND_VAL                                                 'a'
         61        DO_ICALL                                         $31     
         62        SEND_VAR                                                 $31
         63        DO_ICALL                                         $32     
         64        SEND_VAR                                                 $32
         65        DO_ICALL                                         $33     
         66        ASSIGN                                                   !6, $33
   32    67        INIT_FCALL                                               'microtime'
         68        SEND_VAL                                                 <true>
         69        DO_ICALL                                         $35     
         70        SUB                                              ~36     $35, !5
         71        ASSIGN_OP                                     1          !3, ~36
   29    72        PRE_INC                                                  !4
         73    >   FETCH_CONSTANT                                   ~39     'N'
         74        IS_SMALLER                                               !4, ~39
         75      > JMPNZ                                                    ~40, ->52
   34    76    >   INIT_FCALL                                               'printf'
         77        SEND_VAL                                                 'array_filter%28%29%3A+%259.2f+seconds%2F%25d+iterations.+%25f+seconds%2Fiteration.%0A'
         78        SEND_VAR                                                 !3
         79        FETCH_CONSTANT                                   ~41     'N'
         80        SEND_VAL                                                 ~41
         81        FETCH_CONSTANT                                   ~42     'N'
         82        DIV                                              ~43     !3, ~42
         83        SEND_VAL                                                 ~43
         84        DO_ICALL                                                 
   38    85        ASSIGN                                                   !3, 0
   39    86        ASSIGN                                                   !4, 0
         87      > JMP                                                      ->114
   40    88    >   INIT_FCALL                                               'microtime'
         89        SEND_VAL                                                 <true>
         90        DO_ICALL                                         $47     
         91        ASSIGN                                                   !5, $47
   41    92        ASSIGN                                                   !6, null
   42    93      > FE_RESET_R                                       $50     !1, ->107
         94    > > FE_FETCH_R                                               $50, !7, ->107
   43    95    >   TYPE_CHECK                                    2  ~51     !6
         96      > JMPNZ_EX                                         ~51     ~51, ->103
         97    >   FETCH_DIM_R                                      ~52     !7, 'a'
         98      > JMPZ_EX                                          ~52     ~52, ->102
         99    >   FETCH_DIM_R                                      ~53     !7, 'a'
        100        IS_SMALLER                                       ~54     ~53, !6
        101        BOOL                                             ~52     ~54
        102    >   BOOL                                             ~51     ~52
        103    > > JMPZ                                                     ~51, ->106
   44   104    >   FETCH_DIM_R                                      ~55     !7, 'a'
        105        ASSIGN                                                   !6, ~55
   42   106    > > JMP                                                      ->94
        107    >   FE_FREE                                                  $50
   47   108        INIT_FCALL                                               'microtime'
        109        SEND_VAL                                                 <true>
        110        DO_ICALL                                         $57     
        111        SUB                                              ~58     $57, !5
        112        ASSIGN_OP                                     1          !3, ~58
   39   113        PRE_INC                                                  !4
        114    >   FETCH_CONSTANT                                   ~61     'N'
        115        IS_SMALLER                                               !4, ~61
        116      > JMPNZ                                                    ~62, ->88
   49   117    >   INIT_FCALL                                               'printf'
        118        SEND_VAL                                                 'foreach+++++++%3A+%259.2f+seconds%2F%25d+iterations.+%25f+seconds%2Fiteration.%0A'
        119        SEND_VAR                                                 !3
        120        FETCH_CONSTANT                                   ~63     'N'
        121        SEND_VAL                                                 ~63
        122        FETCH_CONSTANT                                   ~64     'N'
        123        DIV                                              ~65     !3, ~64
        124        SEND_VAL                                                 ~65
        125        DO_ICALL                                                 
   53   126        ASSIGN                                                   !3, 0
   54   127        ASSIGN                                                   !4, 0
        128      > JMP                                                      ->145
   55   129    >   INIT_FCALL                                               'microtime'
        130        SEND_VAL                                                 <true>
        131        DO_ICALL                                         $69     
        132        ASSIGN                                                   !5, $69
   56   133        INIT_FCALL                                               'array_reduce'
        134        SEND_VAR                                                 !1
        135        DECLARE_LAMBDA_FUNCTION                          ~71     [0]
   58   136        SEND_VAL                                                 ~71
   56   137        DO_ICALL                                         $72     
        138        ASSIGN                                                   !6, $72
   59   139        INIT_FCALL                                               'microtime'
        140        SEND_VAL                                                 <true>
        141        DO_ICALL                                         $74     
        142        SUB                                              ~75     $74, !5
        143        ASSIGN_OP                                     1          !3, ~75
   54   144        PRE_INC                                                  !4
        145    >   FETCH_CONSTANT                                   ~78     'N'
        146        IS_SMALLER                                               !4, ~78
        147      > JMPNZ                                                    ~79, ->129
   61   148    >   INIT_FCALL                                               'printf'
        149        SEND_VAL                                                 'reduce+%40deceze%3A+%259.2f+seconds%2F%25d+iterations.+%25f+seconds%2Fiteration.%0A'
        150        SEND_VAR                                                 !3
        151        FETCH_CONSTANT                                   ~80     'N'
        152        SEND_VAL                                                 ~80
        153        FETCH_CONSTANT                                   ~81     'N'
        154        DIV                                              ~82     !3, ~81
        155        SEND_VAL                                                 ~82
        156        DO_ICALL                                                 
   65   157        ASSIGN                                                   !3, 0
   66   158        ASSIGN                                                   !4, 0
        159      > JMP                                                      ->177
   67   160    >   INIT_FCALL                                               'microtime'
        161        SEND_VAL                                                 <true>
        162        DO_ICALL                                         $86     
        163        ASSIGN                                                   !5, $86
   68   164        INIT_FCALL                                               'array_reduce'
   69   165        SEND_VAR                                                 !1
   70   166        DECLARE_LAMBDA_FUNCTION                          ~88     [1]
   72   167        SEND_VAL                                                 ~88
   73   168        SEND_VAL                                                 INF
   68   169        DO_ICALL                                         $89     
        170        ASSIGN                                                   !6, $89
   75   171        INIT_FCALL                                               'microtime'
        172        SEND_VAL                                                 <true>
        173        DO_ICALL                                         $91     
        174        SUB                                              ~92     $91, !5
        175        ASSIGN_OP                                     1          !3, ~92
   66   176        PRE_INC                                                  !4
        177    >   FETCH_CONSTANT                                   ~95     'N'
        178        IS_SMALLER                                               !4, ~95
        179      > JMPNZ                                                    ~96, ->160
   77   180    >   INIT_FCALL                                               'printf'
        181        SEND_VAL                                                 'reduce+%40axiac+%3A+%259.2f+seconds%2F%25d+iterations.+%25f+seconds%2Fiteration.%0A'
        182        SEND_VAR                                                 !3
        183        FETCH_CONSTANT                                   ~97     'N'
        184        SEND_VAL                                                 ~97
        185        FETCH_CONSTANT                                   ~98     'N'
        186        DIV                                              ~99     !3, ~98
        187        SEND_VAL                                                 ~99
        188        DO_ICALL                                                 
        189      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
Branch analysis from position: 10
filename:       /in/1CEqE
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $min, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   57     2        TYPE_CHECK                                    2  ~2      !0
          3      > JMPNZ_EX                                         ~2      ~2, ->10
          4    >   FETCH_DIM_R                                      ~3      !1, 'a'
          5      > JMPZ_EX                                          ~3      ~3, ->9
          6    >   FETCH_DIM_R                                      ~4      !1, 'a'
          7        IS_SMALLER                                       ~5      ~4, !0
          8        BOOL                                             ~3      ~5
          9    >   BOOL                                             ~2      ~3
         10    > > JMPZ                                                     ~2, ->14
         11    >   FETCH_DIM_R                                      ~6      !1, 'a'
         12        QM_ASSIGN                                        ~7      ~6
         13      > JMP                                                      ->15
         14    >   QM_ASSIGN                                        ~7      !0
         15    > > RETURN                                                   ~7
   58    16*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1CEqE
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $acc, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   71     2        INIT_FCALL                                               'min'
          3        SEND_VAR                                                 !0
          4        FETCH_DIM_R                                      ~2      !1, 'a'
          5        JMP_SET                                          ~3      ~2, ->7
          6        QM_ASSIGN                                        ~3      INF
          7        SEND_VAL                                                 ~3
          8        DO_ICALL                                         $4      
          9      > RETURN                                                   $4
   72    10*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.98 ms | 1033 KiB | 23 Q