3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* TESTING: http://programmers.stackexchange.com/questions/120378/is-error-suppression-acceptable-in-role-of-logic-mechanism/120386#120386 Elapsed Time[µseconds] Check, Exists : 50000 - Check, Exists : 94718 (user), 342 (system) EACH - Check, Exists : 1.89436E-6 (user), 6.84E-9 (system) Suppress, Exists : 50000 - Suppress, Exists : 146815 (user), 170 (system) EACH - Suppress, Exists : 2.9363E-6 (user), 3.4E-9 (system) Check, Missing : 50000 - Check, Missing : 84252 (user), 82 (system) EACH - Check, Missing : 1.68504E-6 (user), 1.64E-9 (system) Suppress, Missing: 50000 - Suppress, Missing: 200548 (user), 297 (system) EACH - Suppress, Missing: 4.01096E-6 (user), 5.94E-9 (system) Exists : 1.6 times slower (user), 0.5 (system) times slower. Missing: 2.4 times slower (user), 3.6 (system) times slower. */ define( 'TIMES', 50000 ); $results = array(); $messages = array( 'Check, Exists ', 'Suppress, Exists ', 'Check, Missing ', 'Suppress, Missing', ); $results[] = run_test( 'test_error_check', array('key'=>'foo','foo'=>'bar' ) ); $results[] = run_test( 'test_error_suppress', array('key'=>'foo','foo'=>'bar' ) ); $results[] = run_test( 'test_error_check', array('key'=>'foo' ) ); $results[] = run_test( 'test_error_suppress', array('key'=>'foo' ) ); $times = TIMES; $denominator = pow(10,6)*TIMES; echo "Elapsed Time[µseconds]"; foreach( $results as $index => $result ) { echo "\n{$messages[$index]}:"; echo "\n\t{$times} - {$messages[$index]}: {$result[0]} (user), {$result[1]} (system)"; $result[0] /= $denominator; $result[1] /= $denominator; echo "\n\tEACH - {$messages[$index]}: {$result[0]} (user), {$result[1]} (system)"; } echo "\n"; $messages = array( 'Exists ', 'Missing', ); for($i=0; $i<2; $i++) { $j = $i*2; $uratio = round($results[$j+1][0]/$results[$j][0],1); $sratio = round($results[$j+1][1]/$results[$j][1],1); echo "\n{$messages[$i]}: {$uratio} times slower (user), {$sratio} (system) times slower."; } echo "\n\n"; function test_error_suppress( $args, $key ) { return @$args[$key]; } function test_error_check( $args, $key ) { return ! empty( $args[$key] ) ? $args[$key] : false; } function run_test( $func_to_test, $args = array() ) { $dat = getrusage(); $utime_before = $dat["ru_utime.tv_sec"].$dat["ru_utime.tv_usec"]; $stime_before = $dat["ru_stime.tv_sec"].$dat["ru_stime.tv_usec"]; for( $i = 0; $i < TIMES; $i++ ) call_user_func( $func_to_test, $args, $args['key'] ); $dat = getrusage(); $utime_after = $dat["ru_utime.tv_sec"].$dat["ru_utime.tv_usec"]; $stime_after = $dat["ru_stime.tv_sec"].$dat["ru_stime.tv_usec"]; $utime_elapsed = ($utime_after - $utime_before); $stime_elapsed = ($stime_after - $stime_before); return array( $utime_elapsed, $stime_elapsed ); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 41, Position 2 = 77
Branch analysis from position: 41
2 jumps found. (Code = 78) Position 1 = 42, Position 2 = 77
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 116
Branch analysis from position: 116
2 jumps found. (Code = 44) Position 1 = 118, Position 2 = 82
Branch analysis from position: 118
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 82
2 jumps found. (Code = 44) Position 1 = 118, Position 2 = 82
Branch analysis from position: 118
Branch analysis from position: 82
Branch analysis from position: 77
filename:       /in/EVKLI
function name:  (null)
number of ops:  120
compiled vars:  !0 = $results, !1 = $messages, !2 = $times, !3 = $denominator, !4 = $result, !5 = $index, !6 = $i, !7 = $j, !8 = $uratio, !9 = $sratio
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'TIMES'
          2        SEND_VAL                                                 50000
          3        DO_ICALL                                                 
   27     4        ASSIGN                                                   !0, <array>
   28     5        ASSIGN                                                   !1, <array>
   35     6        INIT_FCALL_BY_NAME                                       'run_test'
          7        SEND_VAL_EX                                              'test_error_check'
          8        SEND_VAL_EX                                              <array>
          9        DO_FCALL                                      0  $14     
         10        ASSIGN_DIM                                               !0
         11        OP_DATA                                                  $14
   36    12        INIT_FCALL_BY_NAME                                       'run_test'
         13        SEND_VAL_EX                                              'test_error_suppress'
         14        SEND_VAL_EX                                              <array>
         15        DO_FCALL                                      0  $16     
         16        ASSIGN_DIM                                               !0
         17        OP_DATA                                                  $16
   37    18        INIT_FCALL_BY_NAME                                       'run_test'
         19        SEND_VAL_EX                                              'test_error_check'
         20        SEND_VAL_EX                                              <array>
         21        DO_FCALL                                      0  $18     
         22        ASSIGN_DIM                                               !0
         23        OP_DATA                                                  $18
   38    24        INIT_FCALL_BY_NAME                                       'run_test'
         25        SEND_VAL_EX                                              'test_error_suppress'
         26        SEND_VAL_EX                                              <array>
         27        DO_FCALL                                      0  $20     
         28        ASSIGN_DIM                                               !0
         29        OP_DATA                                                  $20
   40    30        FETCH_CONSTANT                                   ~21     'TIMES'
         31        ASSIGN                                                   !2, ~21
   41    32        INIT_FCALL                                               'pow'
         33        SEND_VAL                                                 10
         34        SEND_VAL                                                 6
         35        DO_ICALL                                         $23     
         36        FETCH_CONSTANT                                   ~24     'TIMES'
         37        MUL                                              ~25     $23, ~24
         38        ASSIGN                                                   !3, ~25
   43    39        ECHO                                                     'Elapsed+Time%5B%C2%B5seconds%5D'
   44    40      > FE_RESET_R                                       $27     !0, ->77
         41    > > FE_FETCH_R                                       ~28     $27, !4, ->77
         42    >   ASSIGN                                                   !5, ~28
   45    43        ROPE_INIT                                     3  ~32     '%0A'
         44        FETCH_DIM_R                                      ~30     !1, !5
         45        ROPE_ADD                                      1  ~32     ~32, ~30
         46        ROPE_END                                      2  ~31     ~32, '%3A'
         47        ECHO                                                     ~31
   46    48        ROPE_INIT                                     9  ~38     '%0A%09'
         49        ROPE_ADD                                      1  ~38     ~38, !2
         50        ROPE_ADD                                      2  ~38     ~38, '+-+'
         51        FETCH_DIM_R                                      ~34     !1, !5
         52        ROPE_ADD                                      3  ~38     ~38, ~34
         53        ROPE_ADD                                      4  ~38     ~38, '%3A+'
         54        FETCH_DIM_R                                      ~35     !4, 0
         55        ROPE_ADD                                      5  ~38     ~38, ~35
         56        ROPE_ADD                                      6  ~38     ~38, '+%28user%29%2C+'
         57        FETCH_DIM_R                                      ~36     !4, 1
         58        ROPE_ADD                                      7  ~38     ~38, ~36
         59        ROPE_END                                      8  ~37     ~38, '+%28system%29'
         60        ECHO                                                     ~37
   47    61        ASSIGN_DIM_OP                /=               4          !4, 0
         62        OP_DATA                                                  !3
   48    63        ASSIGN_DIM_OP                /=               4          !4, 1
         64        OP_DATA                                                  !3
   49    65        ROPE_INIT                                     7  ~49     '%0A%09EACH++-+'
         66        FETCH_DIM_R                                      ~45     !1, !5
         67        ROPE_ADD                                      1  ~49     ~49, ~45
         68        ROPE_ADD                                      2  ~49     ~49, '%3A+'
         69        FETCH_DIM_R                                      ~46     !4, 0
         70        ROPE_ADD                                      3  ~49     ~49, ~46
         71        ROPE_ADD                                      4  ~49     ~49, '+%28user%29%2C+'
         72        FETCH_DIM_R                                      ~47     !4, 1
         73        ROPE_ADD                                      5  ~49     ~49, ~47
         74        ROPE_END                                      6  ~48     ~49, '+%28system%29'
         75        ECHO                                                     ~48
   44    76      > JMP                                                      ->41
         77    >   FE_FREE                                                  $27
   51    78        ECHO                                                     '%0A'
   53    79        ASSIGN                                                   !1, <array>
   57    80        ASSIGN                                                   !6, 0
         81      > JMP                                                      ->116
   58    82    >   MUL                                              ~55     !6, 2
         83        ASSIGN                                                   !7, ~55
   59    84        INIT_FCALL                                               'round'
         85        ADD                                              ~57     !7, 1
         86        FETCH_DIM_R                                      ~58     !0, ~57
         87        FETCH_DIM_R                                      ~59     ~58, 0
         88        FETCH_DIM_R                                      ~60     !0, !7
         89        FETCH_DIM_R                                      ~61     ~60, 0
         90        DIV                                              ~62     ~59, ~61
         91        SEND_VAL                                                 ~62
         92        SEND_VAL                                                 1
         93        DO_ICALL                                         $63     
         94        ASSIGN                                                   !8, $63
   60    95        INIT_FCALL                                               'round'
         96        ADD                                              ~65     !7, 1
         97        FETCH_DIM_R                                      ~66     !0, ~65
         98        FETCH_DIM_R                                      ~67     ~66, 1
         99        FETCH_DIM_R                                      ~68     !0, !7
        100        FETCH_DIM_R                                      ~69     ~68, 1
        101        DIV                                              ~70     ~67, ~69
        102        SEND_VAL                                                 ~70
        103        SEND_VAL                                                 1
        104        DO_ICALL                                         $71     
        105        ASSIGN                                                   !9, $71
   61   106        ROPE_INIT                                     7  ~75     '%0A'
        107        FETCH_DIM_R                                      ~73     !1, !6
        108        ROPE_ADD                                      1  ~75     ~75, ~73
        109        ROPE_ADD                                      2  ~75     ~75, '%3A+'
        110        ROPE_ADD                                      3  ~75     ~75, !8
        111        ROPE_ADD                                      4  ~75     ~75, '+times+slower+%28user%29%2C+'
        112        ROPE_ADD                                      5  ~75     ~75, !9
        113        ROPE_END                                      6  ~74     ~75, '+%28system%29+times+slower.'
        114        ECHO                                                     ~74
   57   115        PRE_INC                                                  !6
        116    >   IS_SMALLER                                               !6, 2
        117      > JMPNZ                                                    ~80, ->82
   63   118    >   ECHO                                                     '%0A%0A'
   91   119      > RETURN                                                   1

Function test_error_suppress:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EVKLI
function name:  test_error_suppress
number of ops:  7
compiled vars:  !0 = $args, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   67     2        BEGIN_SILENCE                                    ~2      
          3        FETCH_DIM_R                                      ~3      !0, !1
          4        END_SILENCE                                              ~2
          5      > RETURN                                                   ~3
   68     6*     > RETURN                                                   null

End of function test_error_suppress

Function test_error_check:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EVKLI
function name:  test_error_check
number of ops:  11
compiled vars:  !0 = $args, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   70     2        ISSET_ISEMPTY_DIM_OBJ                         1  ~2      !0, !1
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->8
          5    >   FETCH_DIM_R                                      ~4      !0, !1
          6        QM_ASSIGN                                        ~5      ~4
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~5      <false>
          9    > > RETURN                                                   ~5
   71    10*     > RETURN                                                   null

End of function test_error_check

Function run_test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 15
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 15
Branch analysis from position: 24
Branch analysis from position: 15
filename:       /in/EVKLI
function name:  run_test
number of ops:  43
compiled vars:  !0 = $func_to_test, !1 = $args, !2 = $dat, !3 = $utime_before, !4 = $stime_before, !5 = $i, !6 = $utime_after, !7 = $stime_after, !8 = $utime_elapsed, !9 = $stime_elapsed
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   75     2        INIT_FCALL                                               'getrusage'
          3        DO_ICALL                                         $10     
          4        ASSIGN                                                   !2, $10
   76     5        FETCH_DIM_R                                      ~12     !2, 'ru_utime.tv_sec'
          6        FETCH_DIM_R                                      ~13     !2, 'ru_utime.tv_usec'
          7        CONCAT                                           ~14     ~12, ~13
          8        ASSIGN                                                   !3, ~14
   77     9        FETCH_DIM_R                                      ~16     !2, 'ru_stime.tv_sec'
         10        FETCH_DIM_R                                      ~17     !2, 'ru_stime.tv_usec'
         11        CONCAT                                           ~18     ~16, ~17
         12        ASSIGN                                                   !4, ~18
   80    13        ASSIGN                                                   !5, 0
         14      > JMP                                                      ->21
   81    15    >   INIT_USER_CALL                                2          'call_user_func', !0
         16        SEND_USER                                                !1
         17        FETCH_DIM_R                                      ~21     !1, 'key'
         18        SEND_USER                                                ~21
         19        DO_FCALL                                      0          
   80    20        PRE_INC                                                  !5
         21    >   FETCH_CONSTANT                                   ~24     'TIMES'
         22        IS_SMALLER                                               !5, ~24
         23      > JMPNZ                                                    ~25, ->15
   83    24    >   INIT_FCALL                                               'getrusage'
         25        DO_ICALL                                         $26     
         26        ASSIGN                                                   !2, $26
   84    27        FETCH_DIM_R                                      ~28     !2, 'ru_utime.tv_sec'
         28        FETCH_DIM_R                                      ~29     !2, 'ru_utime.tv_usec'
         29        CONCAT                                           ~30     ~28, ~29
         30        ASSIGN                                                   !6, ~30
   85    31        FETCH_DIM_R                                      ~32     !2, 'ru_stime.tv_sec'
         32        FETCH_DIM_R                                      ~33     !2, 'ru_stime.tv_usec'
         33        CONCAT                                           ~34     ~32, ~33
         34        ASSIGN                                                   !7, ~34
   87    35        SUB                                              ~36     !6, !3
         36        ASSIGN                                                   !8, ~36
   88    37        SUB                                              ~38     !7, !4
         38        ASSIGN                                                   !9, ~38
   90    39        INIT_ARRAY                                       ~40     !8
         40        ADD_ARRAY_ELEMENT                                ~40     !9
         41      > RETURN                                                   ~40
   91    42*     > RETURN                                                   null

End of function run_test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.53 ms | 1412 KiB | 21 Q