3v4l.org

run code in 300+ 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 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 25
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 39
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 39
Branch analysis from position: 47
Branch analysis from position: 39
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 25
Branch analysis from position: 33
Branch analysis from position: 25
filename:       /in/GYbWC
function name:  (null)
number of ops:  60
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        INIT_FCALL                                               'implode'
         13        SEND_VAL                                                 '%7C'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $17     
         16        CONCAT                                           ~18     '%2F', $17
         17        CONCAT                                           ~19     ~18, '%2F'
         18        ASSIGN                                                   !5, ~19
   43    19        INIT_FCALL                                               'microtime'
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $21     
         22        ASSIGN                                                   !6, $21
   45    23        ASSIGN                                                   !7, 0
         24      > JMP                                                      ->31
   46    25    >   INIT_FCALL                                               'fuckedcaptcha'
         26        SEND_VAR                                                 !0
         27        SEND_VAR                                                 !5
         28        SEND_VAR                                                 !2
         29        DO_FCALL                                      0          
   45    30        PRE_INC                                                  !7
         31    >   IS_SMALLER                                               !7, 100000
         32      > JMPNZ                                                    ~26, ->25
   48    33    >   INIT_FCALL                                               'microtime'
         34        SEND_VAL                                                 <true>
         35        DO_ICALL                                         $27     
         36        ASSIGN                                                   !8, $27
   50    37        ASSIGN                                                   !7, 0
         38      > JMP                                                      ->45
   51    39    >   INIT_FCALL                                               'fastcaptcha'
         40        SEND_VAR                                                 !4
         41        SEND_VAR                                                 !3
         42        SEND_VAR                                                 !2
         43        DO_FCALL                                      0          
   50    44        PRE_INC                                                  !7
         45    >   IS_SMALLER                                               !7, 100000
         46      > JMPNZ                                                    ~32, ->39
   53    47    >   INIT_FCALL                                               'microtime'
         48        SEND_VAL                                                 <true>
         49        DO_ICALL                                         $33     
         50        ASSIGN                                                   !9, $33
   55    51        SUB                                              ~35     !8, !6
         52        CONCAT                                           ~36     'regexp+++++%3A+', ~35
         53        CONCAT                                           ~37     ~36, '%0A'
         54        ECHO                                                     ~37
   56    55        SUB                                              ~38     !9, !8
         56        CONCAT                                           ~39     'array+index%3A+', ~38
         57        CONCAT                                           ~40     ~39, '%0A'
         58        ECHO                                                     ~40
         59      > 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 = 21, Position 2 = 3
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
filename:       /in/GYbWC
function name:  fuckedCaptcha
number of ops:  25
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                                               'substr'
          4        INIT_FCALL                                               'str_shuffle'
          5        INIT_FCALL                                               'str_repeat'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 3
          8        DO_ICALL                                         $4      
          9        SEND_VAR                                                 $4
         10        DO_ICALL                                         $5      
         11        SEND_VAR                                                 $5
         12        SEND_VAL                                                 0
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $6      
         15        ASSIGN                                                   !3, $6
   37    16        INIT_FCALL                                               'preg_match'
         17        SEND_VAR                                                 !1
         18        SEND_VAR                                                 !3
         19        DO_ICALL                                         $8      
         20      > JMPNZ                                                    $8, ->3
   39    21    >   VERIFY_RETURN_TYPE                                       !3
         22      > RETURN                                                   !3
   40    23*       VERIFY_RETURN_TYPE                                       
         24*     > RETURN                                                   null

End of function fuckedcaptcha

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.87 ms | 1018 KiB | 24 Q