3v4l.org

run code in 300+ PHP versions simultaneously
<?php $foo = array(); function slow($foo) { // Slower if (isset($foo) && is_array($foo)) { return true; } } function fast($foo) { // Faster if (isset($foo)) { if (is_array($foo)) { return true; } } } function benchmark($callback, $times) { echo "Testing $callback - Valid\n"; $s = microtime(true); for ($i = 0; $i < $times; $i++) { $callback(array(1, 2, 3)); } $e = microtime(true); echo "Completed in " . ($e - $s) . " Seconds\n"; echo "Testing $callback - Invalid\n"; $s = microtime(true); for ($i = 0; $i < $times; $i++) { $callback("string"); } $e = microtime(true); echo "Completed in " . ($e - $s) . " Seconds\n"; echo "Testing $callback - null\n"; $s = microtime(true); for ($i = 0; $i < $times; $i++) { $callback(null); } $e = microtime(true); echo "Completed in " . ($e - $s) . " Seconds\n"; } benchmark("slow", 1000); benchmark("fast", 1000);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DndhE
function name:  (null)
number of ops:  10
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   39     1        INIT_FCALL                                               'benchmark'
          2        SEND_VAL                                                 'slow'
          3        SEND_VAL                                                 1000
          4        DO_FCALL                                      0          
   40     5        INIT_FCALL                                               'benchmark'
          6        SEND_VAL                                                 'fast'
          7        SEND_VAL                                                 1000
          8        DO_FCALL                                      0          
          9      > RETURN                                                   1

Function slow:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
filename:       /in/DndhE
function name:  slow
number of ops:  8
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2      > JMPZ_EX                                          ~1      ~1, ->5
          3    >   TYPE_CHECK                                  128  ~2      !0
          4        BOOL                                             ~1      ~2
          5    > > JMPZ                                                     ~1, ->7
          6    > > RETURN                                                   <true>
    8     7    > > RETURN                                                   null

End of function slow

Function fast:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/DndhE
function name:  fast
number of ops:  7
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        ISSET_ISEMPTY_CV                                         !0
          2      > JMPZ                                                     ~1, ->6
          3    >   TYPE_CHECK                                  128          !0
          4      > JMPZ                                                     ~2, ->6
          5    > > RETURN                                                   <true>
   13     6    > > RETURN                                                   null

End of function fast

Function benchmark:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 12
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 36
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
2 jumps found. (Code = 44) Position 1 = 66, Position 2 = 60
Branch analysis from position: 66
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 66, Position 2 = 60
Branch analysis from position: 66
Branch analysis from position: 60
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 36
Branch analysis from position: 42
Branch analysis from position: 36
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 12
Branch analysis from position: 18
Branch analysis from position: 12
filename:       /in/DndhE
function name:  benchmark
number of ops:  75
compiled vars:  !0 = $callback, !1 = $times, !2 = $s, !3 = $i, !4 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        ROPE_INIT                                     3  ~6      'Testing+'
          3        ROPE_ADD                                      1  ~6      ~6, !0
          4        ROPE_END                                      2  ~5      ~6, '+-+Valid%0A'
          5        ECHO                                                     ~5
   17     6        INIT_FCALL                                               'microtime'
          7        SEND_VAL                                                 <true>
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !2, $8
   18    10        ASSIGN                                                   !3, 0
         11      > JMP                                                      ->16
   19    12    >   INIT_DYNAMIC_CALL                                        !0
         13        SEND_VAL_EX                                              <array>
         14        DO_FCALL                                      0          
   18    15        PRE_INC                                                  !3
         16    >   IS_SMALLER                                               !3, !1
         17      > JMPNZ                                                    ~13, ->12
   21    18    >   INIT_FCALL                                               'microtime'
         19        SEND_VAL                                                 <true>
         20        DO_ICALL                                         $14     
         21        ASSIGN                                                   !4, $14
   22    22        SUB                                              ~16     !4, !2
         23        CONCAT                                           ~17     'Completed+in+', ~16
         24        CONCAT                                           ~18     ~17, '+Seconds%0A'
         25        ECHO                                                     ~18
   23    26        ROPE_INIT                                     3  ~20     'Testing+'
         27        ROPE_ADD                                      1  ~20     ~20, !0
         28        ROPE_END                                      2  ~19     ~20, '+-+Invalid%0A'
         29        ECHO                                                     ~19
   24    30        INIT_FCALL                                               'microtime'
         31        SEND_VAL                                                 <true>
         32        DO_ICALL                                         $22     
         33        ASSIGN                                                   !2, $22
   25    34        ASSIGN                                                   !3, 0
         35      > JMP                                                      ->40
   26    36    >   INIT_DYNAMIC_CALL                                        !0
         37        SEND_VAL_EX                                              'string'
         38        DO_FCALL                                      0          
   25    39        PRE_INC                                                  !3
         40    >   IS_SMALLER                                               !3, !1
         41      > JMPNZ                                                    ~27, ->36
   28    42    >   INIT_FCALL                                               'microtime'
         43        SEND_VAL                                                 <true>
         44        DO_ICALL                                         $28     
         45        ASSIGN                                                   !4, $28
   29    46        SUB                                              ~30     !4, !2
         47        CONCAT                                           ~31     'Completed+in+', ~30
         48        CONCAT                                           ~32     ~31, '+Seconds%0A'
         49        ECHO                                                     ~32
   30    50        ROPE_INIT                                     3  ~34     'Testing+'
         51        ROPE_ADD                                      1  ~34     ~34, !0
         52        ROPE_END                                      2  ~33     ~34, '+-+null%0A'
         53        ECHO                                                     ~33
   31    54        INIT_FCALL                                               'microtime'
         55        SEND_VAL                                                 <true>
         56        DO_ICALL                                         $36     
         57        ASSIGN                                                   !2, $36
   32    58        ASSIGN                                                   !3, 0
         59      > JMP                                                      ->64
   33    60    >   INIT_DYNAMIC_CALL                                        !0
         61        SEND_VAL_EX                                              null
         62        DO_FCALL                                      0          
   32    63        PRE_INC                                                  !3
         64    >   IS_SMALLER                                               !3, !1
         65      > JMPNZ                                                    ~41, ->60
   35    66    >   INIT_FCALL                                               'microtime'
         67        SEND_VAL                                                 <true>
         68        DO_ICALL                                         $42     
         69        ASSIGN                                                   !4, $42
   36    70        SUB                                              ~44     !4, !2
         71        CONCAT                                           ~45     'Completed+in+', ~44
         72        CONCAT                                           ~46     ~45, '+Seconds%0A'
         73        ECHO                                                     ~46
   37    74      > RETURN                                                   null

End of function benchmark

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.82 ms | 1407 KiB | 17 Q