3v4l.org

run code in 300+ PHP versions simultaneously
<?php function realValue($value) { if ( is_string($value) && strpos($value, '"SuperClosure\Serialize"') !== false ){ return 'closure!'; } return $value; } function rand_string($len) { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $size = strlen($chars); $str = null; for ($i = 0; $i < $len; $i++) { $str .= $chars[ rand( 0, $size - 1 ) ]; } return $str; } $records = []; for ($i = 1; $i <= 2000; $i++) { $records[$i] = rand_string(1000); } // Ignore above, just generate a random string with 20,000 records. $read_value = null; $realValue_bench_start = microtime(true); foreach ($records as $record) { $read_value = realValue($record); } $realValue_bench_end = microtime(true); $directAccess_bench_start = microtime(true); foreach ($records as $record) { $read_value = $record; } $directAccess_bench_end = microtime(true); $diffRealValue = $realValue_bench_end - $realValue_bench_start; $diffDirectAccess = $directAccess_bench_end - $directAccess_bench_start; echo("readValue time: $diffRealValue"); echo("\ndirectAccess time: $diffDirectAccess"); echo("\ndifference:" . ($diffRealValue - $diffDirectAccess));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 3
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 23
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
Branch analysis from position: 23
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 3
Branch analysis from position: 11
Branch analysis from position: 3
filename:       /in/72arb
function name:  (null)
number of ops:  55
compiled vars:  !0 = $records, !1 = $i, !2 = $read_value, !3 = $realValue_bench_start, !4 = $record, !5 = $realValue_bench_end, !6 = $directAccess_bench_start, !7 = $directAccess_bench_end, !8 = $diffRealValue, !9 = $diffDirectAccess
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ASSIGN                                                   !0, <array>
   29     1        ASSIGN                                                   !1, 1
          2      > JMP                                                      ->9
   30     3    >   INIT_FCALL                                               'rand_string'
          4        SEND_VAL                                                 1000
          5        DO_FCALL                                      0  $13     
          6        ASSIGN_DIM                                               !0, !1
          7        OP_DATA                                                  $13
   29     8        PRE_INC                                                  !1
          9    >   IS_SMALLER_OR_EQUAL                                      !1, 2000
         10      > JMPNZ                                                    ~15, ->3
   35    11    >   ASSIGN                                                   !2, null
   37    12        INIT_FCALL                                               'microtime'
         13        SEND_VAL                                                 <true>
         14        DO_ICALL                                         $17     
         15        ASSIGN                                                   !3, $17
   39    16      > FE_RESET_R                                       $19     !0, ->23
         17    > > FE_FETCH_R                                               $19, !4, ->23
   40    18    >   INIT_FCALL                                               'realvalue'
         19        SEND_VAR                                                 !4
         20        DO_FCALL                                      0  $20     
         21        ASSIGN                                                   !2, $20
   39    22      > JMP                                                      ->17
         23    >   FE_FREE                                                  $19
   43    24        INIT_FCALL                                               'microtime'
         25        SEND_VAL                                                 <true>
         26        DO_ICALL                                         $22     
         27        ASSIGN                                                   !5, $22
   45    28        INIT_FCALL                                               'microtime'
         29        SEND_VAL                                                 <true>
         30        DO_ICALL                                         $24     
         31        ASSIGN                                                   !6, $24
   46    32      > FE_RESET_R                                       $26     !0, ->36
         33    > > FE_FETCH_R                                               $26, !4, ->36
   47    34    >   ASSIGN                                                   !2, !4
   46    35      > JMP                                                      ->33
         36    >   FE_FREE                                                  $26
   49    37        INIT_FCALL                                               'microtime'
         38        SEND_VAL                                                 <true>
         39        DO_ICALL                                         $28     
         40        ASSIGN                                                   !7, $28
   51    41        SUB                                              ~30     !5, !3
         42        ASSIGN                                                   !8, ~30
   52    43        SUB                                              ~32     !7, !6
         44        ASSIGN                                                   !9, ~32
   53    45        NOP                                                      
         46        FAST_CONCAT                                      ~34     'readValue+time%3A+', !8
         47        ECHO                                                     ~34
   54    48        NOP                                                      
         49        FAST_CONCAT                                      ~35     '%0AdirectAccess+time%3A+', !9
         50        ECHO                                                     ~35
   55    51        SUB                                              ~36     !8, !9
         52        CONCAT                                           ~37     '%0Adifference%3A', ~36
         53        ECHO                                                     ~37
         54      > RETURN                                                   1

Function realvalue:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/72arb
function name:  realValue
number of ops:  13
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    6     1        TYPE_CHECK                                   64  ~1      !0
          2      > JMPZ_EX                                          ~1      ~1, ->9
    7     3    >   INIT_FCALL                                               'strpos'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 '%22SuperClosure%5CSerialize%22'
          6        DO_ICALL                                         $2      
          7        TYPE_CHECK                                  1018  ~3      $2
          8        BOOL                                             ~1      ~3
          9    > > JMPZ                                                     ~1, ->11
    9    10    > > RETURN                                                   'closure%21'
   12    11    > > RETURN                                                   !0
   13    12*     > RETURN                                                   null

End of function realvalue

Function rand_string:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 7
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 7
Branch analysis from position: 17
Branch analysis from position: 7
filename:       /in/72arb
function name:  rand_string
number of ops:  19
compiled vars:  !0 = $len, !1 = $chars, !2 = $size, !3 = $str, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        ASSIGN                                                   !1, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
   17     2        STRLEN                                           ~6      !1
          3        ASSIGN                                                   !2, ~6
   18     4        ASSIGN                                                   !3, null
   20     5        ASSIGN                                                   !4, 0
          6      > JMP                                                      ->15
   21     7    >   INIT_FCALL                                               'rand'
          8        SEND_VAL                                                 0
          9        SUB                                              ~10     !2, 1
         10        SEND_VAL                                                 ~10
         11        DO_ICALL                                         $11     
         12        FETCH_DIM_R                                      ~12     !1, $11
         13        ASSIGN_OP                                     8          !3, ~12
   20    14        PRE_INC                                                  !4
         15    >   IS_SMALLER                                               !4, !0
         16      > JMPNZ                                                    ~15, ->7
   24    17    > > RETURN                                                   !3
   25    18*     > RETURN                                                   null

End of function rand_string

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.04 ms | 1407 KiB | 21 Q