3v4l.org

run code in 300+ PHP versions simultaneously
<?php class X { protected $val = []; function notempty() { return ! empty( $this->val ); } function booltest() { return (bool) $this->val; } } $its = 1e3; $x = new X; $t = hrtime(true); for ($i=0;$i++<$its;) $x->notempty(); echo (hrtime(true)-$t)/1e9,"s\n"; $t = hrtime(true); for ($i=0;$i++<$its;) $x->booltest(); echo (hrtime(true)-$t)/1e9,"s\n"; echo "\n=== Warmed up ===\n\n"; $its = 1e5; $t = hrtime(true); for ($i=0;$i++<$its;) $x->notempty(); echo 'notempty: ', $a=(hrtime(true)-$t)/1e9,"s\n"; $t = hrtime(true); for ($i=0;$i++<$its;) $x->booltest(); echo 'bool : ', $b=(hrtime(true)-$t)/1e9,"s\n"; echo 'bool is ', number_format((($a-$b)/$a) * 100, 2 ), "% faster than notempty chain\n";
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 = 15, Position 2 = 10
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 28
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 48
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
2 jumps found. (Code = 44) Position 1 = 73, Position 2 = 68
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 73, Position 2 = 68
Branch analysis from position: 73
Branch analysis from position: 68
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 48
Branch analysis from position: 53
Branch analysis from position: 48
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 28
Branch analysis from position: 33
Branch analysis from position: 28
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 10
Branch analysis from position: 15
Branch analysis from position: 10
filename:       /in/P4PHh
function name:  (null)
number of ops:  93
compiled vars:  !0 = $its, !1 = $x, !2 = $t, !3 = $i, !4 = $a, !5 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, 1000
   18     1        NEW                                              $7      'X'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
   20     4        INIT_FCALL                                               'hrtime'
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !2, $10
   21     8        ASSIGN                                                   !3, 0
          9      > JMP                                                      ->12
   22    10    >   INIT_METHOD_CALL                                         !1, 'notempty'
         11        DO_FCALL                                      0          
   21    12    >   POST_INC                                         ~14     !3
         13        IS_SMALLER                                               ~14, !0
         14      > JMPNZ                                                    ~15, ->10
   23    15    >   INIT_FCALL                                               'hrtime'
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $16     
         18        SUB                                              ~17     $16, !2
         19        DIV                                              ~18     ~17, 1.0e+9
         20        ECHO                                                     ~18
         21        ECHO                                                     's%0A'
   25    22        INIT_FCALL                                               'hrtime'
         23        SEND_VAL                                                 <true>
         24        DO_ICALL                                         $19     
         25        ASSIGN                                                   !2, $19
   26    26        ASSIGN                                                   !3, 0
         27      > JMP                                                      ->30
   27    28    >   INIT_METHOD_CALL                                         !1, 'booltest'
         29        DO_FCALL                                      0          
   26    30    >   POST_INC                                         ~23     !3
         31        IS_SMALLER                                               ~23, !0
         32      > JMPNZ                                                    ~24, ->28
   28    33    >   INIT_FCALL                                               'hrtime'
         34        SEND_VAL                                                 <true>
         35        DO_ICALL                                         $25     
         36        SUB                                              ~26     $25, !2
         37        DIV                                              ~27     ~26, 1.0e+9
         38        ECHO                                                     ~27
         39        ECHO                                                     's%0A'
   30    40        ECHO                                                     '%0A%3D%3D%3D+Warmed+up+%3D%3D%3D%0A%0A'
   32    41        ASSIGN                                                   !0, 100000
   34    42        INIT_FCALL                                               'hrtime'
         43        SEND_VAL                                                 <true>
         44        DO_ICALL                                         $29     
         45        ASSIGN                                                   !2, $29
   35    46        ASSIGN                                                   !3, 0
         47      > JMP                                                      ->50
   36    48    >   INIT_METHOD_CALL                                         !1, 'notempty'
         49        DO_FCALL                                      0          
   35    50    >   POST_INC                                         ~33     !3
         51        IS_SMALLER                                               ~33, !0
         52      > JMPNZ                                                    ~34, ->48
   37    53    >   ECHO                                                     'notempty%3A+'
         54        INIT_FCALL                                               'hrtime'
         55        SEND_VAL                                                 <true>
         56        DO_ICALL                                         $35     
         57        SUB                                              ~36     $35, !2
         58        DIV                                              ~37     ~36, 1.0e+9
         59        ASSIGN                                           ~38     !4, ~37
         60        ECHO                                                     ~38
         61        ECHO                                                     's%0A'
   39    62        INIT_FCALL                                               'hrtime'
         63        SEND_VAL                                                 <true>
         64        DO_ICALL                                         $39     
         65        ASSIGN                                                   !2, $39
   40    66        ASSIGN                                                   !3, 0
         67      > JMP                                                      ->70
   41    68    >   INIT_METHOD_CALL                                         !1, 'booltest'
         69        DO_FCALL                                      0          
   40    70    >   POST_INC                                         ~43     !3
         71        IS_SMALLER                                               ~43, !0
         72      > JMPNZ                                                    ~44, ->68
   42    73    >   ECHO                                                     'bool++++%3A+'
         74        INIT_FCALL                                               'hrtime'
         75        SEND_VAL                                                 <true>
         76        DO_ICALL                                         $45     
         77        SUB                                              ~46     $45, !2
         78        DIV                                              ~47     ~46, 1.0e+9
         79        ASSIGN                                           ~48     !5, ~47
         80        ECHO                                                     ~48
         81        ECHO                                                     's%0A'
   44    82        ECHO                                                     'bool+is+'
         83        INIT_FCALL                                               'number_format'
         84        SUB                                              ~49     !4, !5
         85        DIV                                              ~50     ~49, !4
         86        MUL                                              ~51     ~50, 100
         87        SEND_VAL                                                 ~51
         88        SEND_VAL                                                 2
         89        DO_ICALL                                         $52     
         90        ECHO                                                     $52
         91        ECHO                                                     '%25+faster+than+notempty+chain%0A'
         92      > RETURN                                                   1

Class X:
Function notempty:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P4PHh
function name:  notempty
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   ISSET_ISEMPTY_PROP_OBJ                           ~0      'val'
          1        BOOL_NOT                                         ~1      ~0
          2      > RETURN                                                   ~1
    9     3*     > RETURN                                                   null

End of function notempty

Function booltest:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P4PHh
function name:  booltest
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   FETCH_OBJ_R                                      ~0      'val'
          1        BOOL                                             ~1      ~0
          2      > RETURN                                                   ~1
   13     3*     > RETURN                                                   null

End of function booltest

End of class X.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.62 ms | 1020 KiB | 15 Q