3v4l.org

run code in 300+ PHP versions simultaneously
<?php function compareA($a, $b) { return strcmp(json_encode($a), json_encode($b)); } function compareB($a, $b) { return strcmp(implode(',', $a), implode(',', $b)); } function array_diff_multi($a, $b) { return array_map('json_decode', array_diff(array_map('json_encode', $a), array_map('json_encode', $b))); } function bench_diff($a, $b, $callback) { for ($i = 0; $i < 1000; $i++) { $c = array_udiff($a, $b, $callback); } $start = microtime(true); for ($i = 0; $i < 1000; $i++) { $c = array_udiff($a, $b, $callback); } $end = microtime(true); echo $callback, "\t", ($end - $start) * 1000, ' ms', PHP_EOL; return $c; } $a = array( array('localhost', 11211, 0), array('localhost', 11211, 0), array('localhost', 11212, 0), array('localhost', 11213, 0), array('localhost', 11214, 0), array('localhost', 11214, 0), array('localhost', 11214, 0), array('localhost', 11212, 0), array('other', 11211, 0), array('localhost', 11211, 0), ); $b = array( array('localhost', 11211, 0), array('other', 11211, 0), array('other', 11212, 0), array('localhost', 11212, 0), array('localhost', 11212, 0), array('localhost', 11213, 0), ); $c = bench_diff($a, $b, 'compareA'); $c = bench_diff($a, $b, 'compareB'); for ($i = 0; $i < 1000; $i++) { $c = array_diff_multi($a, $b); } $start = microtime(true); for ($i = 0; $i < 1000; $i++) { $c = array_diff_multi($a, $b); } $end = microtime(true); echo "diff-json\t", ($end - $start) * 1000, ' ms', PHP_EOL; var_export($c);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 16
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 30
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 30
Branch analysis from position: 38
Branch analysis from position: 30
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 16
Branch analysis from position: 24
Branch analysis from position: 16
filename:       /in/OfTLK
function name:  (null)
number of ops:  52
compiled vars:  !0 = $a, !1 = $b, !2 = $c, !3 = $i, !4 = $start, !5 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                   !0, <array>
   40     1        ASSIGN                                                   !1, <array>
   49     2        INIT_FCALL                                               'bench_diff'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 'compareA'
          6        DO_FCALL                                      0  $8      
          7        ASSIGN                                                   !2, $8
   50     8        INIT_FCALL                                               'bench_diff'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        SEND_VAL                                                 'compareB'
         12        DO_FCALL                                      0  $10     
         13        ASSIGN                                                   !2, $10
   52    14        ASSIGN                                                   !3, 0
         15      > JMP                                                      ->22
   53    16    >   INIT_FCALL                                               'array_diff_multi'
         17        SEND_VAR                                                 !0
         18        SEND_VAR                                                 !1
         19        DO_FCALL                                      0  $13     
         20        ASSIGN                                                   !2, $13
   52    21        PRE_INC                                                  !3
         22    >   IS_SMALLER                                               !3, 1000
         23      > JMPNZ                                                    ~16, ->16
   55    24    >   INIT_FCALL                                               'microtime'
         25        SEND_VAL                                                 <true>
         26        DO_ICALL                                         $17     
         27        ASSIGN                                                   !4, $17
   56    28        ASSIGN                                                   !3, 0
         29      > JMP                                                      ->36
   57    30    >   INIT_FCALL                                               'array_diff_multi'
         31        SEND_VAR                                                 !0
         32        SEND_VAR                                                 !1
         33        DO_FCALL                                      0  $20     
         34        ASSIGN                                                   !2, $20
   56    35        PRE_INC                                                  !3
         36    >   IS_SMALLER                                               !3, 1000
         37      > JMPNZ                                                    ~23, ->30
   59    38    >   INIT_FCALL                                               'microtime'
         39        SEND_VAL                                                 <true>
         40        DO_ICALL                                         $24     
         41        ASSIGN                                                   !5, $24
   60    42        ECHO                                                     'diff-json%09'
         43        SUB                                              ~26     !5, !4
         44        MUL                                              ~27     ~26, 1000
         45        ECHO                                                     ~27
         46        ECHO                                                     '+ms'
         47        ECHO                                                     '%0A'
   62    48        INIT_FCALL                                               'var_export'
         49        SEND_VAR                                                 !2
         50        DO_ICALL                                                 
         51      > RETURN                                                   1

Function comparea:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OfTLK
function name:  compareA
number of ops:  14
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_FCALL                                               'strcmp'
          3        INIT_FCALL                                               'json_encode'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        SEND_VAR                                                 $2
          7        INIT_FCALL                                               'json_encode'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $3      
         10        SEND_VAR                                                 $3
         11        DO_ICALL                                         $4      
         12      > RETURN                                                   $4
    5    13*     > RETURN                                                   null

End of function comparea

Function compareb:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OfTLK
function name:  compareB
number of ops:  16
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        INIT_FCALL                                               'strcmp'
          3        INIT_FCALL                                               'implode'
          4        SEND_VAL                                                 '%2C'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7        SEND_VAR                                                 $2
          8        INIT_FCALL                                               'implode'
          9        SEND_VAL                                                 '%2C'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $3      
         12        SEND_VAR                                                 $3
         13        DO_ICALL                                         $4      
         14      > RETURN                                                   $4
    9    15*     > RETURN                                                   null

End of function compareb

Function array_diff_multi:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OfTLK
function name:  array_diff_multi
number of ops:  20
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        INIT_FCALL                                               'array_map'
          3        SEND_VAL                                                 'json_decode'
          4        INIT_FCALL                                               'array_diff'
          5        INIT_FCALL                                               'array_map'
          6        SEND_VAL                                                 'json_encode'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $2      
          9        SEND_VAR                                                 $2
         10        INIT_FCALL                                               'array_map'
         11        SEND_VAL                                                 'json_encode'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $3      
         14        SEND_VAR                                                 $3
         15        DO_ICALL                                         $4      
         16        SEND_VAR                                                 $4
         17        DO_ICALL                                         $5      
         18      > RETURN                                                   $5
   13    19*     > RETURN                                                   null

End of function array_diff_multi

Function bench_diff:
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 = 14, Position 2 = 5
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 20
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 20
Branch analysis from position: 29
Branch analysis from position: 20
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 5
Branch analysis from position: 14
Branch analysis from position: 5
filename:       /in/OfTLK
function name:  bench_diff
number of ops:  42
compiled vars:  !0 = $a, !1 = $b, !2 = $callback, !3 = $i, !4 = $c, !5 = $start, !6 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   16     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->12
   17     5    >   INIT_FCALL                                               'array_udiff'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                         $8      
         10        ASSIGN                                                   !4, $8
   16    11        PRE_INC                                                  !3
         12    >   IS_SMALLER                                               !3, 1000
         13      > JMPNZ                                                    ~11, ->5
   19    14    >   INIT_FCALL                                               'microtime'
         15        SEND_VAL                                                 <true>
         16        DO_ICALL                                         $12     
         17        ASSIGN                                                   !5, $12
   20    18        ASSIGN                                                   !3, 0
         19      > JMP                                                      ->27
   21    20    >   INIT_FCALL                                               'array_udiff'
         21        SEND_VAR                                                 !0
         22        SEND_VAR                                                 !1
         23        SEND_VAR                                                 !2
         24        DO_ICALL                                         $15     
         25        ASSIGN                                                   !4, $15
   20    26        PRE_INC                                                  !3
         27    >   IS_SMALLER                                               !3, 1000
         28      > JMPNZ                                                    ~18, ->20
   23    29    >   INIT_FCALL                                               'microtime'
         30        SEND_VAL                                                 <true>
         31        DO_ICALL                                         $19     
         32        ASSIGN                                                   !6, $19
   24    33        ECHO                                                     !2
         34        ECHO                                                     '%09'
         35        SUB                                              ~21     !6, !5
         36        MUL                                              ~22     ~21, 1000
         37        ECHO                                                     ~22
         38        ECHO                                                     '+ms'
         39        ECHO                                                     '%0A'
   25    40      > RETURN                                                   !4
   26    41*     > RETURN                                                   null

End of function bench_diff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.6 ms | 1402 KiB | 33 Q