3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set( 'display_errors', 1 ); error_reporting( E_ALL ); // Make a bit, honkin test array // You may need to adjust this depth to avoid memory limit errors $testArray = fillArray( 0, 5 ); // Time json encoding $start = microtime( true ); json_encode( $testArray ); $jsonTime = microtime( true ) - $start; echo "JSON encoded in $jsonTime seconds<br>"; // Time serialization $start = microtime( true ); serialize( $testArray ); $serializeTime = microtime( true ) - $start; echo "PHP serialized in $serializeTime seconds<br>"; // Compare them if ( $jsonTime < $serializeTime ) { echo "json_encode() was roughly " . number_format( ($serializeTime / $jsonTime - 1 ) * 100, 2 ) . "% faster than serialize()"; } else if ( $serializeTime < $jsonTime ) { echo "serialize() was roughly " . number_format( ($jsonTime / $serializeTime - 1 ) * 100, 2 ) . "% faster than json_encode()"; } else { echo 'Unpossible!'; } function fillArray( $depth, $max ) { static $seed; if ( is_null( $seed ) ) { $seed = array( 'a', 2, 'c', 4, 'e', 6, 'g', 8, 'i', 10 ); } if ( $depth < $max ) { $node = array(); foreach ( $seed as $key ) { $node[$key] = fillArray( $depth + 1, $max ); } return $node; } return 'empty'; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 57
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 70
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qFKvT
function name:  (null)
number of ops:  72
compiled vars:  !0 = $testArray, !1 = $start, !2 = $jsonTime, !3 = $serializeTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'ini_set'
          1        SEND_VAL                                                 'display_errors'
          2        SEND_VAL                                                 1
          3        DO_ICALL                                                 
    4     4        INIT_FCALL                                               'error_reporting'
          5        SEND_VAL                                                 32767
          6        DO_ICALL                                                 
    8     7        INIT_FCALL_BY_NAME                                       'fillArray'
          8        SEND_VAL_EX                                              0
          9        SEND_VAL_EX                                              5
         10        DO_FCALL                                      0  $6      
         11        ASSIGN                                                   !0, $6
   11    12        INIT_FCALL                                               'microtime'
         13        SEND_VAL                                                 <true>
         14        DO_ICALL                                         $8      
         15        ASSIGN                                                   !1, $8
   12    16        INIT_FCALL                                               'json_encode'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                                 
   13    19        INIT_FCALL                                               'microtime'
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $11     
         22        SUB                                              ~12     $11, !1
         23        ASSIGN                                                   !2, ~12
   14    24        ROPE_INIT                                     3  ~15     'JSON+encoded+in+'
         25        ROPE_ADD                                      1  ~15     ~15, !2
         26        ROPE_END                                      2  ~14     ~15, '+seconds%3Cbr%3E'
         27        ECHO                                                     ~14
   17    28        INIT_FCALL                                               'microtime'
         29        SEND_VAL                                                 <true>
         30        DO_ICALL                                         $17     
         31        ASSIGN                                                   !1, $17
   18    32        INIT_FCALL                                               'serialize'
         33        SEND_VAR                                                 !0
         34        DO_ICALL                                                 
   19    35        INIT_FCALL                                               'microtime'
         36        SEND_VAL                                                 <true>
         37        DO_ICALL                                         $20     
         38        SUB                                              ~21     $20, !1
         39        ASSIGN                                                   !3, ~21
   20    40        ROPE_INIT                                     3  ~24     'PHP+serialized+in+'
         41        ROPE_ADD                                      1  ~24     ~24, !3
         42        ROPE_END                                      2  ~23     ~24, '+seconds%3Cbr%3E'
         43        ECHO                                                     ~23
   23    44        IS_SMALLER                                               !2, !3
         45      > JMPZ                                                     ~26, ->57
   25    46    >   INIT_FCALL                                               'number_format'
         47        DIV                                              ~27     !3, !2
         48        SUB                                              ~28     ~27, 1
         49        MUL                                              ~29     ~28, 100
         50        SEND_VAL                                                 ~29
         51        SEND_VAL                                                 2
         52        DO_ICALL                                         $30     
         53        CONCAT                                           ~31     'json_encode%28%29+was+roughly+', $30
         54        CONCAT                                           ~32     ~31, '%25+faster+than+serialize%28%29'
         55        ECHO                                                     ~32
         56      > JMP                                                      ->71
   27    57    >   IS_SMALLER                                               !3, !2
         58      > JMPZ                                                     ~33, ->70
   29    59    >   INIT_FCALL                                               'number_format'
         60        DIV                                              ~34     !2, !3
         61        SUB                                              ~35     ~34, 1
         62        MUL                                              ~36     ~35, 100
         63        SEND_VAL                                                 ~36
         64        SEND_VAL                                                 2
         65        DO_ICALL                                         $37     
         66        CONCAT                                           ~38     'serialize%28%29+was+roughly+', $37
         67        CONCAT                                           ~39     ~38, '%25+faster+than+json_encode%28%29'
         68        ECHO                                                     ~39
         69      > JMP                                                      ->71
   31    70    >   ECHO                                                     'Unpossible%21'
   51    71    > > RETURN                                                   1

Function fillarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 21
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 19
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 19
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/qFKvT
function name:  fillArray
number of ops:  23
compiled vars:  !0 = $depth, !1 = $max, !2 = $seed, !3 = $node, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   36     2        BIND_STATIC                                              !2
   37     3        TYPE_CHECK                                    2          !2
          4      > JMPZ                                                     ~5, ->6
   39     5    >   ASSIGN                                                   !2, <array>
   41     6    >   IS_SMALLER                                               !0, !1
          7      > JMPZ                                                     ~7, ->21
   43     8    >   ASSIGN                                                   !3, <array>
   44     9      > FE_RESET_R                                       $9      !2, ->19
         10    > > FE_FETCH_R                                               $9, !4, ->19
   46    11    >   INIT_FCALL_BY_NAME                                       'fillArray'
         12        ADD                                              ~11     !0, 1
         13        SEND_VAL_EX                                              ~11
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0  $12     
         16        ASSIGN_DIM                                               !3, !4
         17        OP_DATA                                                  $12
   44    18      > JMP                                                      ->10
         19    >   FE_FREE                                                  $9
   48    20      > RETURN                                                   !3
   50    21    > > RETURN                                                   'empty'
   51    22*     > RETURN                                                   null

End of function fillarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
187.35 ms | 1404 KiB | 25 Q