3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set('display_errors', 1); error_reporting(E_ALL); // Make a big, 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) { printf("json_encode() was roughly %01.2f%% faster than serialize()\n", ($serializeTime / $jsonTime - 1) * 100); } elseif ($serializeTime < $jsonTime ) { printf("serialize() was roughly %01.2f%% faster than json_encode()\n", ($jsonTime / $serializeTime - 1) * 100); } else { echo "Unpossible!\n"; } 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 = 54
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 64
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/abfKH
function name:  (null)
number of ops:  66
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%0A'
         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%0A'
         43        ECHO                                                     ~23
   23    44        IS_SMALLER                                               !2, !3
         45      > JMPZ                                                     ~26, ->54
   24    46    >   INIT_FCALL                                               'printf'
         47        SEND_VAL                                                 'json_encode%28%29+was+roughly+%2501.2f%25%25+faster+than+serialize%28%29%0A'
         48        DIV                                              ~27     !3, !2
         49        SUB                                              ~28     ~27, 1
         50        MUL                                              ~29     ~28, 100
         51        SEND_VAL                                                 ~29
         52        DO_ICALL                                                 
   23    53      > JMP                                                      ->65
   26    54    >   IS_SMALLER                                               !3, !2
         55      > JMPZ                                                     ~31, ->64
   27    56    >   INIT_FCALL                                               'printf'
         57        SEND_VAL                                                 'serialize%28%29+was+roughly+%2501.2f%25%25+faster+than+json_encode%28%29%0A'
         58        DIV                                              ~32     !2, !3
         59        SUB                                              ~33     ~32, 1
         60        MUL                                              ~34     ~33, 100
         61        SEND_VAL                                                 ~34
         62        DO_ICALL                                                 
   26    63      > JMP                                                      ->65
   29    64    >   ECHO                                                     'Unpossible%21%0A'
   45    65    > > 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/abfKH
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
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   33     2        BIND_STATIC                                              !2
   34     3        TYPE_CHECK                                    2          !2
          4      > JMPZ                                                     ~5, ->6
   35     5    >   ASSIGN                                                   !2, <array>
   37     6    >   IS_SMALLER                                               !0, !1
          7      > JMPZ                                                     ~7, ->21
   38     8    >   ASSIGN                                                   !3, <array>
   39     9      > FE_RESET_R                                       $9      !2, ->19
         10    > > FE_FETCH_R                                               $9, !4, ->19
   40    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
   39    18      > JMP                                                      ->10
         19    >   FE_FREE                                                  $9
   42    20      > RETURN                                                   !3
   44    21    > > RETURN                                                   'empty'
   45    22*     > RETURN                                                   null

End of function fillarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
132.03 ms | 1467 KiB | 19 Q