3v4l.org

run code in 500+ PHP versions simultaneously
<?php $str = "23456789ABCDEGHJKMNPQRSTUVXYZabcdeghjkmnpqrstuvxyz"; $excludes = ['cp','cb','ck','c6','c9','rn','rm','mm','co','do','cl','db','qp','qb','dp','ww']; $length = 5; $indexedExcludes = array_combine($excludes, $excludes); $dictionaryArray = str_split($str); function fastCaptcha(array $dictionary, array $excludedSyllables, int $length): string { $captcha = ''; $previousCharacter = ''; $generatedLength = 0; while ($generatedLength < $length) { $randomCharacter = $dictionary[array_rand($dictionary)]; if(array_key_exists($previousCharacter . $randomCharacter, $excludedSyllables)) { continue; } $captcha .= $randomCharacter; $previousCharacter = $randomCharacter; $generatedLength++; } return $captcha; } $excludesRegex = '/' . implode('|', $excludes) . '/'; function fuckedCaptcha(string $dictionary, string $excludedSyllables, int $length): string { do { $code = substr(str_shuffle(str_repeat($dictionary, 3)), 0, $length); } while (preg_match($excludedSyllables, $code)); return $code; } $t0 = microtime(true); for ($i = 0; $i < 100000; $i++) fuckedCaptcha($str, $excludesRegex, $length); $t1 = microtime(true); for ($i = 0; $i < 100000; $i++) fastCaptcha($dictionaryArray, $indexedExcludes, $length); $t2 = microtime(true); echo "regexp : " . ($t1 - $t0) . "\n"; echo "array index: " . ($t2 - $t1) . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 22
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 36
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 36
Branch analysis from position: 44
Branch analysis from position: 36
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 22
Branch analysis from position: 30
Branch analysis from position: 22
filename:       /in/GYbWC
function name:  (null)
number of ops:  57
compiled vars:  !0 = $str, !1 = $excludes, !2 = $length, !3 = $indexedExcludes, !4 = $dictionaryArray, !5 = $excludesRegex, !6 = $t0, !7 = $i, !8 = $t1, !9 = $t2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '23456789ABCDEGHJKMNPQRSTUVXYZabcdeghjkmnpqrstuvxyz'
    4     1        ASSIGN                                                       !1, <array>
    5     2        ASSIGN                                                       !2, 5
    7     3        INIT_FCALL                                                   'array_combine'
          4        SEND_VAR                                                     !1
          5        SEND_VAR                                                     !1
          6        DO_ICALL                                             $13     
          7        ASSIGN                                                       !3, $13
    8     8        INIT_FCALL                                                   'str_split'
          9        SEND_VAR                                                     !0
         10        DO_ICALL                                             $15     
         11        ASSIGN                                                       !4, $15
   31    12        FRAMELESS_ICALL_2                implode             ~17     '%7C', !1
         13        CONCAT                                               ~18     '%2F', ~17
         14        CONCAT                                               ~19     ~18, '%2F'
         15        ASSIGN                                                       !5, ~19
   43    16        INIT_FCALL                                                   'microtime'
         17        SEND_VAL                                                     <true>
         18        DO_ICALL                                             $21     
         19        ASSIGN                                                       !6, $21
   45    20        ASSIGN                                                       !7, 0
         21      > JMP                                                          ->28
   46    22    >   INIT_FCALL                                                   'fuckedcaptcha'
         23        SEND_VAR                                                     !0
         24        SEND_VAR                                                     !5
         25        SEND_VAR                                                     !2
         26        DO_FCALL                                          0          
   45    27        PRE_INC                                                      !7
         28    >   IS_SMALLER                                                   !7, 100000
         29      > JMPNZ                                                        ~26, ->22
   48    30    >   INIT_FCALL                                                   'microtime'
         31        SEND_VAL                                                     <true>
         32        DO_ICALL                                             $27     
         33        ASSIGN                                                       !8, $27
   50    34        ASSIGN                                                       !7, 0
         35      > JMP                                                          ->42
   51    36    >   INIT_FCALL                                                   'fastcaptcha'
         37        SEND_VAR                                                     !4
         38        SEND_VAR                                                     !3
         39        SEND_VAR                                                     !2
         40        DO_FCALL                                          0          
   50    41        PRE_INC                                                      !7
         42    >   IS_SMALLER                                                   !7, 100000
         43      > JMPNZ                                                        ~32, ->36
   53    44    >   INIT_FCALL                                                   'microtime'
         45        SEND_VAL                                                     <true>
         46        DO_ICALL                                             $33     
         47        ASSIGN                                                       !9, $33
   55    48        SUB                                                  ~35     !8, !6
         49        CONCAT                                               ~36     'regexp+++++%3A+', ~35
         50        CONCAT                                               ~37     ~36, '%0A'
         51        ECHO                                                         ~37
   56    52        SUB                                                  ~38     !9, !8
         53        CONCAT                                               ~39     'array+index%3A+', ~38
         54        CONCAT                                               ~40     ~39, '%0A'
         55        ECHO                                                         ~40
         56      > RETURN                                                       1

Function fastcaptcha:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 7
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 7
Branch analysis from position: 21
Branch analysis from position: 7
filename:       /in/GYbWC
function name:  fastCaptcha
number of ops:  25
compiled vars:  !0 = $dictionary, !1 = $excludedSyllables, !2 = $length, !3 = $captcha, !4 = $previousCharacter, !5 = $generatedLength, !6 = $randomCharacter
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   12     3        ASSIGN                                                       !3, ''
   13     4        ASSIGN                                                       !4, ''
   14     5        ASSIGN                                                       !5, 0
   16     6      > JMP                                                          ->19
   17     7    >   INIT_FCALL                                                   'array_rand'
          8        SEND_VAR                                                     !0
          9        DO_ICALL                                             $10     
         10        FETCH_DIM_R                                          ~11     !0, $10
         11        ASSIGN                                                       !6, ~11
   19    12        CONCAT                                               ~13     !4, !6
         13        ARRAY_KEY_EXISTS                                             ~13, !1
         14      > JMPZ                                                         ~14, ->16
   20    15    > > JMP                                                          ->19
   23    16    >   ASSIGN_OP                                         8          !3, !6
   24    17        ASSIGN                                                       !4, !6
   25    18        PRE_INC                                                      !5
   16    19    >   IS_SMALLER                                                   !5, !2
         20      > JMPNZ                                                        ~18, ->7
   28    21    >   VERIFY_RETURN_TYPE                                           !3
         22      > RETURN                                                       !3
   29    23*       VERIFY_RETURN_TYPE                                           
         24*     > RETURN                                                       null

End of function fastcaptcha

Function fuckedcaptcha:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 3
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
filename:       /in/GYbWC
function name:  fuckedCaptcha
number of ops:  19
compiled vars:  !0 = $dictionary, !1 = $excludedSyllables, !2 = $length, !3 = $code
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   33     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   36     3    >   INIT_FCALL                                                   'str_shuffle'
          4        INIT_FCALL                                                   'str_repeat'
          5        SEND_VAR                                                     !0
          6        SEND_VAL                                                     3
          7        DO_ICALL                                             $4      
          8        SEND_VAR                                                     $4
          9        DO_ICALL                                             $5      
         10        FRAMELESS_ICALL_3                substr              ~6      $5, 0
         11        OP_DATA                                                      !2
         12        ASSIGN                                                       !3, ~6
   37    13        FRAMELESS_ICALL_2                preg_match          ~8      !1, !3
         14      > JMPNZ                                                        ~8, ->3
   39    15    >   VERIFY_RETURN_TYPE                                           !3
         16      > RETURN                                                       !3
   40    17*       VERIFY_RETURN_TYPE                                           
         18*     > RETURN                                                       null

End of function fuckedcaptcha

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
182.01 ms | 3016 KiB | 21 Q