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 = 38, Position 2 = 49
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 62
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UvrB5
function name:  (null)
number of ops:  64
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
   17    24        INIT_FCALL                                               'microtime'
         25        SEND_VAL                                                 <true>
         26        DO_ICALL                                         $14     
         27        ASSIGN                                                   !1, $14
   18    28        INIT_FCALL                                               'serialize'
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                                 
   19    31        INIT_FCALL                                               'microtime'
         32        SEND_VAL                                                 <true>
         33        DO_ICALL                                         $17     
         34        SUB                                              ~18     $17, !1
         35        ASSIGN                                                   !3, ~18
   23    36        IS_SMALLER                                               !2, !3
         37      > JMPZ                                                     ~20, ->49
   25    38    >   INIT_FCALL                                               'number_format'
         39        DIV                                              ~21     !3, !2
         40        SUB                                              ~22     ~21, 1
         41        MUL                                              ~23     ~22, 100
         42        SEND_VAL                                                 ~23
         43        SEND_VAL                                                 2
         44        DO_ICALL                                         $24     
         45        CONCAT                                           ~25     'json_encode%28%29+was+roughly+', $24
         46        CONCAT                                           ~26     ~25, '%25+faster+than+serialize%28%29'
         47        ECHO                                                     ~26
         48      > JMP                                                      ->63
   27    49    >   IS_SMALLER                                               !3, !2
         50      > JMPZ                                                     ~27, ->62
   29    51    >   INIT_FCALL                                               'number_format'
         52        DIV                                              ~28     !2, !3
         53        SUB                                              ~29     ~28, 1
         54        MUL                                              ~30     ~29, 100
         55        SEND_VAL                                                 ~30
         56        SEND_VAL                                                 2
         57        DO_ICALL                                         $31     
         58        CONCAT                                           ~32     'serialize%28%29+was+roughly+', $31
         59        CONCAT                                           ~33     ~32, '%25+faster+than+json_encode%28%29'
         60        ECHO                                                     ~33
         61      > JMP                                                      ->63
   31    62    >   ECHO                                                     'Unpossible%21'
   51    63    > > 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/UvrB5
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:
156.25 ms | 1404 KiB | 25 Q