3v4l.org

run code in 300+ PHP versions simultaneously
<?php $iterations = 100000; function str_random($length=16) { $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; return substr(str_shuffle(str_repeat($pool, 5)), 0, $length); } $strings = array(); for ($i = 0; $i < $iterations; $i++) { $strings[] = str_random(rand(16, 64)); } echo 'String size: ', round(strlen(serialize($strings))/ 1024, 2), 'kb', PHP_EOL; $hashes_md5 = array(); $hashes_crc32 = array(); $t_md5 = microtime(true); foreach ($strings as $s) { $hashes_md5['x'.(crc32($s) >> 8)] = 0; } $t_md5 = microtime(true) - $t_md5; //$max = bindec('111111111111111111111111111111'); //$max = 0xFFFFFFF; //F; +5% size boost, collision: 0.1689%, time boost: 0% $max = 0xFFFFFF; //FF; +14% size boost, collision: 2.908%, time boost: -9% //$max = 0xFFFFF; //FFF; +47% size boost, collision: 35.5696%, time boost: 0% // modify 10% of data for ($i = 0; $i < $iterations; $i++) { if (rand(1,100) > 90) { $strings[$i] = openssl_random_pseudo_bytes(rand(16, 50)); } } $t_crc32 = microtime(true); foreach ($strings as $s) { $hashes_crc32['x'.(crc32($s) >> 8)] = 0; } $t_crc32 = microtime(true) - $t_crc32; function compareShingles(array $first, array $second) { $t_crc32 = microtime(true); echo 'func intersect: ', count(array_intersect_key($first, $second)), PHP_EOL; echo ' func unique: ', count(array_merge($first, $second)), PHP_EOL; $t_crc32 = microtime(true) - $t_crc32; echo ' time: ', $t_crc32, PHP_EOL; $t_crc32 = microtime(true); $diff_count = count(array_diff_key($first, $second)); $intersect_count = count($first) - $diff_count;// count(array_intersect_key($first, $second)); $unique_count = count($second) + $diff_count; echo 'calculated intersect: ', $intersect_count, PHP_EOL; echo ' calculated unique: ', $unique_count, PHP_EOL; $t_crc32 = microtime(true) - $t_crc32; echo ' time: ', $t_crc32, PHP_EOL; //return round(($intersect_count / $unique_count) / 0.01, 2); } $hashes_md5_flip = $hashes_md5; //array_flip($hashes_md5); $hashes_crc32_flip = $hashes_crc32; //array_flip($hashes_crc32); //ksort($hashes_md5_flip); //ksort($hashes_crc32_flip); $t_merge = microtime(true); $hashes_diff = array_diff_key($hashes_md5_flip, $hashes_crc32_flip); $t_merge = microtime(true) - $t_merge; $t_diff = microtime(true); $hashes_merge = array_merge($hashes_md5_flip, $hashes_crc32_flip); $t_diff = microtime(true) - $t_diff; $t_intersect = microtime(true); $hashes_intersect = array_intersect_key($hashes_md5_flip, $hashes_crc32_flip); $t_intersect = microtime(true) - $t_intersect; echo PHP_EOL; echo ' merge time: ', $t_merge, PHP_EOL; echo ' merge count: ', count($hashes_merge), PHP_EOL; echo ' diff time: ', $t_merge, PHP_EOL; echo ' diff count: ', count($hashes_diff), PHP_EOL; echo ' intersect time: ', $t_intersect, PHP_EOL; echo 'intersect count: ', count($hashes_intersect), PHP_EOL; echo ' md5 count: ', count($hashes_md5_flip), ' with diff:', count($hashes_md5_flip)+count($hashes_diff), ' intersect: ', count($hashes_md5_flip)-count($hashes_diff), PHP_EOL; echo ' crc32 count: ', count($hashes_crc32_flip), ' with diff:', count($hashes_crc32_flip)+count($hashes_diff), ' intersect: ', count($hashes_crc32_flip)-count($hashes_diff), PHP_EOL; echo PHP_EOL; compareShingles($hashes_md5_flip, $hashes_crc32_flip); echo PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 4
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 36, Position 2 = 45
Branch analysis from position: 36
2 jumps found. (Code = 78) Position 1 = 37, Position 2 = 45
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
2 jumps found. (Code = 44) Position 1 = 72, Position 2 = 54
Branch analysis from position: 72
2 jumps found. (Code = 77) Position 1 = 77, Position 2 = 86
Branch analysis from position: 77
2 jumps found. (Code = 78) Position 1 = 78, Position 2 = 86
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
Branch analysis from position: 86
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 86
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 69
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 72, Position 2 = 54
Branch analysis from position: 72
Branch analysis from position: 54
Branch analysis from position: 69
Branch analysis from position: 45
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 4
Branch analysis from position: 16
Branch analysis from position: 4
filename:       /in/sKc0W
function name:  (null)
number of ops:  193
compiled vars:  !0 = $iterations, !1 = $strings, !2 = $i, !3 = $hashes_md5, !4 = $hashes_crc32, !5 = $t_md5, !6 = $s, !7 = $max, !8 = $t_crc32, !9 = $hashes_md5_flip, !10 = $hashes_crc32_flip, !11 = $t_merge, !12 = $hashes_diff, !13 = $t_diff, !14 = $hashes_merge, !15 = $t_intersect, !16 = $hashes_intersect
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 100000
   12     1        ASSIGN                                                   !1, <array>
   14     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->14
   15     4    >   INIT_FCALL                                               'str_random'
          5        INIT_FCALL                                               'rand'
          6        SEND_VAL                                                 16
          7        SEND_VAL                                                 64
          8        DO_ICALL                                         $21     
          9        SEND_VAR                                                 $21
         10        DO_FCALL                                      0  $22     
         11        ASSIGN_DIM                                               !1
         12        OP_DATA                                                  $22
   14    13        PRE_INC                                                  !2
         14    >   IS_SMALLER                                               !2, !0
         15      > JMPNZ                                                    ~24, ->4
   18    16    >   ECHO                                                     'String+size%3A+'
         17        INIT_FCALL                                               'round'
         18        INIT_FCALL                                               'serialize'
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $25     
         21        STRLEN                                           ~26     $25
         22        DIV                                              ~27     ~26, 1024
         23        SEND_VAL                                                 ~27
         24        SEND_VAL                                                 2
         25        DO_ICALL                                         $28     
         26        ECHO                                                     $28
         27        ECHO                                                     'kb'
         28        ECHO                                                     '%0A'
   20    29        ASSIGN                                                   !3, <array>
   21    30        ASSIGN                                                   !4, <array>
   23    31        INIT_FCALL                                               'microtime'
         32        SEND_VAL                                                 <true>
         33        DO_ICALL                                         $31     
         34        ASSIGN                                                   !5, $31
   24    35      > FE_RESET_R                                       $33     !1, ->45
         36    > > FE_FETCH_R                                               $33, !6, ->45
   25    37    >   INIT_FCALL                                               'crc32'
         38        SEND_VAR                                                 !6
         39        DO_ICALL                                         $34     
         40        SR                                               ~35     $34, 8
         41        CONCAT                                           ~36     'x', ~35
         42        ASSIGN_DIM                                               !3, ~36
         43        OP_DATA                                                  0
   24    44      > JMP                                                      ->36
         45    >   FE_FREE                                                  $33
   27    46        INIT_FCALL                                               'microtime'
         47        SEND_VAL                                                 <true>
         48        DO_ICALL                                         $38     
         49        SUB                                              ~39     $38, !5
         50        ASSIGN                                                   !5, ~39
   31    51        ASSIGN                                                   !7, 16777215
   35    52        ASSIGN                                                   !2, 0
         53      > JMP                                                      ->70
   36    54    >   INIT_FCALL                                               'rand'
         55        SEND_VAL                                                 1
         56        SEND_VAL                                                 100
         57        DO_ICALL                                         $43     
         58        IS_SMALLER                                               90, $43
         59      > JMPZ                                                     ~44, ->69
   37    60    >   INIT_FCALL_BY_NAME                                       'openssl_random_pseudo_bytes'
         61        INIT_FCALL                                               'rand'
         62        SEND_VAL                                                 16
         63        SEND_VAL                                                 50
         64        DO_ICALL                                         $46     
         65        SEND_VAR_NO_REF_EX                                       $46
         66        DO_FCALL                                      0  $47     
         67        ASSIGN_DIM                                               !1, !2
         68        OP_DATA                                                  $47
   35    69    >   PRE_INC                                                  !2
         70    >   IS_SMALLER                                               !2, !0
         71      > JMPNZ                                                    ~49, ->54
   41    72    >   INIT_FCALL                                               'microtime'
         73        SEND_VAL                                                 <true>
         74        DO_ICALL                                         $50     
         75        ASSIGN                                                   !8, $50
   42    76      > FE_RESET_R                                       $52     !1, ->86
         77    > > FE_FETCH_R                                               $52, !6, ->86
   43    78    >   INIT_FCALL                                               'crc32'
         79        SEND_VAR                                                 !6
         80        DO_ICALL                                         $53     
         81        SR                                               ~54     $53, 8
         82        CONCAT                                           ~55     'x', ~54
         83        ASSIGN_DIM                                               !4, ~55
         84        OP_DATA                                                  0
   42    85      > JMP                                                      ->77
         86    >   FE_FREE                                                  $52
   45    87        INIT_FCALL                                               'microtime'
         88        SEND_VAL                                                 <true>
         89        DO_ICALL                                         $57     
         90        SUB                                              ~58     $57, !8
         91        ASSIGN                                                   !8, ~58
   69    92        ASSIGN                                                   !9, !3
   70    93        ASSIGN                                                   !10, !4
   75    94        INIT_FCALL                                               'microtime'
         95        SEND_VAL                                                 <true>
         96        DO_ICALL                                         $62     
         97        ASSIGN                                                   !11, $62
   76    98        INIT_FCALL                                               'array_diff_key'
         99        SEND_VAR                                                 !9
        100        SEND_VAR                                                 !10
        101        DO_ICALL                                         $64     
        102        ASSIGN                                                   !12, $64
   77   103        INIT_FCALL                                               'microtime'
        104        SEND_VAL                                                 <true>
        105        DO_ICALL                                         $66     
        106        SUB                                              ~67     $66, !11
        107        ASSIGN                                                   !11, ~67
   79   108        INIT_FCALL                                               'microtime'
        109        SEND_VAL                                                 <true>
        110        DO_ICALL                                         $69     
        111        ASSIGN                                                   !13, $69
   80   112        INIT_FCALL                                               'array_merge'
        113        SEND_VAR                                                 !9
        114        SEND_VAR                                                 !10
        115        DO_ICALL                                         $71     
        116        ASSIGN                                                   !14, $71
   81   117        INIT_FCALL                                               'microtime'
        118        SEND_VAL                                                 <true>
        119        DO_ICALL                                         $73     
        120        SUB                                              ~74     $73, !13
        121        ASSIGN                                                   !13, ~74
   83   122        INIT_FCALL                                               'microtime'
        123        SEND_VAL                                                 <true>
        124        DO_ICALL                                         $76     
        125        ASSIGN                                                   !15, $76
   84   126        INIT_FCALL                                               'array_intersect_key'
        127        SEND_VAR                                                 !9
        128        SEND_VAR                                                 !10
        129        DO_ICALL                                         $78     
        130        ASSIGN                                                   !16, $78
   85   131        INIT_FCALL                                               'microtime'
        132        SEND_VAL                                                 <true>
        133        DO_ICALL                                         $80     
        134        SUB                                              ~81     $80, !15
        135        ASSIGN                                                   !15, ~81
   87   136        ECHO                                                     '%0A'
   89   137        ECHO                                                     '++merge+time%3A+'
        138        ECHO                                                     !11
        139        ECHO                                                     '%0A'
   90   140        ECHO                                                     '+merge+count%3A+'
        141        COUNT                                            ~83     !14
        142        ECHO                                                     ~83
        143        ECHO                                                     '%0A'
   91   144        ECHO                                                     '+++diff+time%3A+'
        145        ECHO                                                     !11
        146        ECHO                                                     '%0A'
   92   147        ECHO                                                     '++diff+count%3A+'
        148        COUNT                                            ~84     !12
        149        ECHO                                                     ~84
        150        ECHO                                                     '%0A'
   93   151        ECHO                                                     '+intersect+time%3A+'
        152        ECHO                                                     !15
        153        ECHO                                                     '%0A'
   94   154        ECHO                                                     'intersect+count%3A+'
        155        COUNT                                            ~85     !16
        156        ECHO                                                     ~85
        157        ECHO                                                     '%0A'
   95   158        ECHO                                                     '+++md5+count%3A+'
        159        COUNT                                            ~86     !9
        160        ECHO                                                     ~86
        161        ECHO                                                     '+with+diff%3A'
        162        COUNT                                            ~87     !9
        163        COUNT                                            ~88     !12
        164        ADD                                              ~89     ~87, ~88
        165        ECHO                                                     ~89
        166        ECHO                                                     '+intersect%3A+'
        167        COUNT                                            ~90     !9
        168        COUNT                                            ~91     !12
        169        SUB                                              ~92     ~90, ~91
        170        ECHO                                                     ~92
        171        ECHO                                                     '%0A'
   96   172        ECHO                                                     '+crc32+count%3A+'
        173        COUNT                                            ~93     !10
        174        ECHO                                                     ~93
        175        ECHO                                                     '+with+diff%3A'
        176        COUNT                                            ~94     !10
        177        COUNT                                            ~95     !12
        178        ADD                                              ~96     ~94, ~95
        179        ECHO                                                     ~96
        180        ECHO                                                     '+intersect%3A+'
        181        COUNT                                            ~97     !10
        182        COUNT                                            ~98     !12
        183        SUB                                              ~99     ~97, ~98
        184        ECHO                                                     ~99
        185        ECHO                                                     '%0A'
   98   186        ECHO                                                     '%0A'
  100   187        INIT_FCALL                                               'compareshingles'
        188        SEND_VAR                                                 !9
        189        SEND_VAR                                                 !10
        190        DO_FCALL                                      0          
  102   191        ECHO                                                     '%0A'
        192      > RETURN                                                   1

Function str_random:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sKc0W
function name:  str_random
number of ops:  16
compiled vars:  !0 = $length, !1 = $pool
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV_INIT                                        !0      16
    6     1        ASSIGN                                                   !1, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    8     2        INIT_FCALL                                               'substr'
          3        INIT_FCALL                                               'str_shuffle'
          4        INIT_FCALL                                               'str_repeat'
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 5
          7        DO_ICALL                                         $3      
          8        SEND_VAR                                                 $3
          9        DO_ICALL                                         $4      
         10        SEND_VAR                                                 $4
         11        SEND_VAL                                                 0
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $5      
         14      > RETURN                                                   $5
   10    15*     > RETURN                                                   null

End of function str_random

Function compareshingles:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sKc0W
function name:  compareShingles
number of ops:  61
compiled vars:  !0 = $first, !1 = $second, !2 = $t_crc32, !3 = $diff_count, !4 = $intersect_count, !5 = $unique_count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   50     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !2, $6
   52     6        ECHO                                                     'func+intersect%3A+'
          7        INIT_FCALL                                               'array_intersect_key'
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $8      
         11        COUNT                                            ~9      $8
         12        ECHO                                                     ~9
         13        ECHO                                                     '%0A'
   53    14        ECHO                                                     '+++func+unique%3A+'
         15        INIT_FCALL                                               'array_merge'
         16        SEND_VAR                                                 !0
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $10     
         19        COUNT                                            ~11     $10
         20        ECHO                                                     ~11
         21        ECHO                                                     '%0A'
   54    22        INIT_FCALL                                               'microtime'
         23        SEND_VAL                                                 <true>
         24        DO_ICALL                                         $12     
         25        SUB                                              ~13     $12, !2
         26        ASSIGN                                                   !2, ~13
   55    27        ECHO                                                     '++++++++++time%3A+'
         28        ECHO                                                     !2
         29        ECHO                                                     '%0A'
   57    30        INIT_FCALL                                               'microtime'
         31        SEND_VAL                                                 <true>
         32        DO_ICALL                                         $15     
         33        ASSIGN                                                   !2, $15
   58    34        INIT_FCALL                                               'array_diff_key'
         35        SEND_VAR                                                 !0
         36        SEND_VAR                                                 !1
         37        DO_ICALL                                         $17     
         38        COUNT                                            ~18     $17
         39        ASSIGN                                                   !3, ~18
   59    40        COUNT                                            ~20     !0
         41        SUB                                              ~21     ~20, !3
         42        ASSIGN                                                   !4, ~21
   60    43        COUNT                                            ~23     !1
         44        ADD                                              ~24     ~23, !3
         45        ASSIGN                                                   !5, ~24
   62    46        ECHO                                                     'calculated+intersect%3A+'
         47        ECHO                                                     !4
         48        ECHO                                                     '%0A'
   63    49        ECHO                                                     '+++calculated+unique%3A+'
         50        ECHO                                                     !5
         51        ECHO                                                     '%0A'
   64    52        INIT_FCALL                                               'microtime'
         53        SEND_VAL                                                 <true>
         54        DO_ICALL                                         $26     
         55        SUB                                              ~27     $26, !2
         56        ASSIGN                                                   !2, ~27
   65    57        ECHO                                                     '++++++++++time%3A+'
         58        ECHO                                                     !2
         59        ECHO                                                     '%0A'
   67    60      > RETURN                                                   null

End of function compareshingles

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.36 ms | 1423 KiB | 37 Q