3v4l.org

run code in 300+ PHP versions simultaneously
<?php // 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\n"; // Time serialization $start = microtime( true ); serialize( $testArray ); $serializeTime = microtime( true ) - $start; echo "PHP serialized in $serializeTime seconds\n"; // 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 = 39, Position 2 = 50
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 63
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TmiXl
function name:  (null)
number of ops:  65
compiled vars:  !0 = $testArray, !1 = $start, !2 = $jsonTime, !3 = $serializeTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   INIT_FCALL_BY_NAME                                       'fillArray'
          1        SEND_VAL_EX                                              0
          2        SEND_VAL_EX                                              5
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !0, $4
    8     5        INIT_FCALL                                               'microtime'
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $6      
          8        ASSIGN                                                   !1, $6
    9     9        INIT_FCALL                                               'json_encode'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                                 
   10    12        INIT_FCALL                                               'microtime'
         13        SEND_VAL                                                 <true>
         14        DO_ICALL                                         $9      
         15        SUB                                              ~10     $9, !1
         16        ASSIGN                                                   !2, ~10
   11    17        ROPE_INIT                                     3  ~13     'JSON+encoded+in+'
         18        ROPE_ADD                                      1  ~13     ~13, !2
         19        ROPE_END                                      2  ~12     ~13, '+seconds%0A'
         20        ECHO                                                     ~12
   14    21        INIT_FCALL                                               'microtime'
         22        SEND_VAL                                                 <true>
         23        DO_ICALL                                         $15     
         24        ASSIGN                                                   !1, $15
   15    25        INIT_FCALL                                               'serialize'
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                                 
   16    28        INIT_FCALL                                               'microtime'
         29        SEND_VAL                                                 <true>
         30        DO_ICALL                                         $18     
         31        SUB                                              ~19     $18, !1
         32        ASSIGN                                                   !3, ~19
   17    33        ROPE_INIT                                     3  ~22     'PHP+serialized+in+'
         34        ROPE_ADD                                      1  ~22     ~22, !3
         35        ROPE_END                                      2  ~21     ~22, '+seconds%0A'
         36        ECHO                                                     ~21
   20    37        IS_SMALLER                                               !2, !3
         38      > JMPZ                                                     ~24, ->50
   22    39    >   INIT_FCALL                                               'number_format'
         40        DIV                                              ~25     !3, !2
         41        SUB                                              ~26     ~25, 1
         42        MUL                                              ~27     ~26, 100
         43        SEND_VAL                                                 ~27
         44        SEND_VAL                                                 2
         45        DO_ICALL                                         $28     
         46        CONCAT                                           ~29     'json_encode%28%29+was+roughly+', $28
         47        CONCAT                                           ~30     ~29, '%25+faster+than+serialize%28%29'
         48        ECHO                                                     ~30
         49      > JMP                                                      ->64
   24    50    >   IS_SMALLER                                               !3, !2
         51      > JMPZ                                                     ~31, ->63
   26    52    >   INIT_FCALL                                               'number_format'
         53        DIV                                              ~32     !2, !3
         54        SUB                                              ~33     ~32, 1
         55        MUL                                              ~34     ~33, 100
         56        SEND_VAL                                                 ~34
         57        SEND_VAL                                                 2
         58        DO_ICALL                                         $35     
         59        CONCAT                                           ~36     'serialize%28%29+was+roughly+', $35
         60        CONCAT                                           ~37     ~36, '%25+faster+than+json_encode%28%29'
         61        ECHO                                                     ~37
         62      > JMP                                                      ->64
   28    63    >   ECHO                                                     'Unpossible%21'
   48    64    > > 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/TmiXl
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
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   33     2        BIND_STATIC                                              !2
   34     3        TYPE_CHECK                                    2          !2
          4      > JMPZ                                                     ~5, ->6
   36     5    >   ASSIGN                                                   !2, <array>
   38     6    >   IS_SMALLER                                               !0, !1
          7      > JMPZ                                                     ~7, ->21
   40     8    >   ASSIGN                                                   !3, <array>
   41     9      > FE_RESET_R                                       $9      !2, ->19
         10    > > FE_FETCH_R                                               $9, !4, ->19
   43    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
   41    18      > JMP                                                      ->10
         19    >   FE_FREE                                                  $9
   45    20      > RETURN                                                   !3
   47    21    > > RETURN                                                   'empty'
   48    22*     > RETURN                                                   null

End of function fillarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.22 ms | 949 KiB | 22 Q