3v4l.org

run code in 300+ PHP versions simultaneously
<?php function benchmark(callable $fn, int $iterations = 1000000) { $start = microtime(true); for ($i = 0; $i < $iterations; $i++) { $fn(); } return microtime(true) - $start; } function benchmarks(array $benchmarks, int $iterations = 1000000) { $results = []; foreach ($benchmarks as $name => $callable) { $results[$name] = benchmark($callable, $iterations); } $maximum = max($results); $minimum = min($results); foreach ($results as $name => $result) { echo "$name: $result"; if ($result === $maximum) { echo ' (slowest)'; } if ($result === $minimum) { echo ' (fastest)'; } echo "\n"; } } $a = ['one' => 1, 'two' => 2, 'three' => 3]; benchmarks([ 'empty' => fn() => empty($a['none']), 'isset' => fn() => isset($a['none']), 'array_key_exists' => fn() => array_key_exists('none', $a), 'null comparison' => fn() => (bool)($a['none'] ?? false), ]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Y1ERg
function name:  (null)
number of ops:  17
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   ASSIGN                                                   !0, <array>
   36     1        INIT_FCALL                                               'benchmarks'
   37     2        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          3        BIND_LEXICAL                                             ~2, !0
          4        INIT_ARRAY                                       ~3      ~2, 'empty'
   38     5        DECLARE_LAMBDA_FUNCTION                          ~4      [1]
          6        BIND_LEXICAL                                             ~4, !0
          7        ADD_ARRAY_ELEMENT                                ~3      ~4, 'isset'
   39     8        DECLARE_LAMBDA_FUNCTION                          ~5      [2]
          9        BIND_LEXICAL                                             ~5, !0
         10        ADD_ARRAY_ELEMENT                                ~3      ~5, 'array_key_exists'
   40    11        DECLARE_LAMBDA_FUNCTION                          ~6      [3]
         12        BIND_LEXICAL                                             ~6, !0
         13        ADD_ARRAY_ELEMENT                                ~3      ~6, 'null+comparison'
         14        SEND_VAL                                                 ~3
   36    15        DO_FCALL                                      0          
   41    16      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Y1ERg
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   BIND_STATIC                                              !0
          1        ISSET_ISEMPTY_DIM_OBJ                         1  ~1      !0, 'none'
          2      > RETURN                                                   ~1
          3*     > 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/Y1ERg
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   BIND_STATIC                                              !0
          1        ISSET_ISEMPTY_DIM_OBJ                         0  ~1      !0, 'none'
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Y1ERg
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   BIND_STATIC                                              !0
          1        ARRAY_KEY_EXISTS                                 ~1      'none', !0
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of Dynamic Function 2

Dynamic Function 3
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Y1ERg
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   BIND_STATIC                                              !0
          1        FETCH_DIM_IS                                     ~1      !0, 'none'
          2        COALESCE                                         ~2      ~1
          3        QM_ASSIGN                                        ~2      <false>
          4        BOOL                                             ~3      ~2
          5      > RETURN                                                   ~3
          6*     > RETURN                                                   null

End of Dynamic Function 3

Function benchmark:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 8
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 8
Branch analysis from position: 13
Branch analysis from position: 8
filename:       /in/Y1ERg
function name:  benchmark
number of ops:  19
compiled vars:  !0 = $fn, !1 = $iterations, !2 = $start, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      1000000
    3     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !2, $4
    5     6        ASSIGN                                                   !3, 0
          7      > JMP                                                      ->11
    6     8    >   INIT_DYNAMIC_CALL                                        !0
          9        DO_FCALL                                      0          
    5    10        PRE_INC                                                  !3
         11    >   IS_SMALLER                                               !3, !1
         12      > JMPNZ                                                    ~9, ->8
    9    13    >   INIT_FCALL                                               'microtime'
         14        SEND_VAL                                                 <true>
         15        DO_ICALL                                         $10     
         16        SUB                                              ~11     $10, !2
         17      > RETURN                                                   ~11
   10    18*     > RETURN                                                   null

End of function benchmark

Function benchmarks:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 37
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 37
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 32
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 35
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 35
Branch analysis from position: 32
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
Branch analysis from position: 13
filename:       /in/Y1ERg
function name:  benchmarks
number of ops:  39
compiled vars:  !0 = $benchmarks, !1 = $iterations, !2 = $results, !3 = $callable, !4 = $name, !5 = $maximum, !6 = $minimum, !7 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      1000000
   13     2        ASSIGN                                                   !2, <array>
   14     3      > FE_RESET_R                                       $9      !0, ->13
          4    > > FE_FETCH_R                                       ~10     $9, !3, ->13
          5    >   ASSIGN                                                   !4, ~10
   15     6        INIT_FCALL                                               'benchmark'
          7        SEND_VAR                                                 !3
          8        SEND_VAR                                                 !1
          9        DO_FCALL                                      0  $13     
         10        ASSIGN_DIM                                               !2, !4
         11        OP_DATA                                                  $13
   14    12      > JMP                                                      ->4
         13    >   FE_FREE                                                  $9
   18    14        INIT_FCALL                                               'max'
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $14     
         17        ASSIGN                                                   !5, $14
   19    18        INIT_FCALL                                               'min'
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                         $16     
         21        ASSIGN                                                   !6, $16
   21    22      > FE_RESET_R                                       $18     !2, ->37
         23    > > FE_FETCH_R                                       ~19     $18, !7, ->37
         24    >   ASSIGN                                                   !4, ~19
   22    25        ROPE_INIT                                     3  ~22     !4
         26        ROPE_ADD                                      1  ~22     ~22, '%3A+'
         27        ROPE_END                                      2  ~21     ~22, !7
         28        ECHO                                                     ~21
   23    29        IS_IDENTICAL                                             !7, !5
         30      > JMPZ                                                     ~24, ->32
   24    31    >   ECHO                                                     '+%28slowest%29'
   26    32    >   IS_IDENTICAL                                             !7, !6
         33      > JMPZ                                                     ~25, ->35
   27    34    >   ECHO                                                     '+%28fastest%29'
   30    35    >   ECHO                                                     '%0A'
   21    36      > JMP                                                      ->23
         37    >   FE_FREE                                                  $18
   32    38      > RETURN                                                   null

End of function benchmarks

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.36 ms | 1024 KiB | 18 Q