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 = [ 'string' => 'string', 'int' => 1, 'float' => 1.1, 'bool' => true, 'date' => new Datetime('now'), 'array' => [ 'string' => 'string', 'int' => 1, 'float' => 1.1, 'bool' => true, 'date' => new Datetime('now'), 'array' => [ 'string' => 'string', 'int' => 1, 'float' => 1.1, 'bool' => true, 'date' => new Datetime('now'), ], ], fillArray(0, 5) ]; $numRuns = 10000000; // Time json encoding $start = microtime( true ); for ($i = 0; $i++; $i <= $numRuns) { json_encode( $testArray ); } $jsonTime = (microtime( true ) - $start); echo "JSON encoded in " . ($jsonTime/$numRuns) . " seconds\n"; // Time serialization $start = microtime( true ); for ($i = 0; $i++; $i <= $numRuns) { serialize( $testArray ); } $serializeTime = (microtime( true ) - $start); echo "PHP serialized in " . ($serializeTime/$numRuns) . " 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 " . ($serializeTime ? number_format( ($jsonTime / $serializeTime - 1) * 100, 2 ) . '%' : 'insanely') . " faster than json_encode()"; } else { echo 'This is a draw'; } 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
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 46
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 68
Branch analysis from position: 75
2 jumps found. (Code = 43) Position 1 = 86, Position 2 = 97
Branch analysis from position: 86
1 jumps found. (Code = 42) Position 1 = 116
Branch analysis from position: 116
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 97
2 jumps found. (Code = 43) Position 1 = 99, Position 2 = 115
Branch analysis from position: 99
2 jumps found. (Code = 43) Position 1 = 100, Position 2 = 110
Branch analysis from position: 100
1 jumps found. (Code = 42) Position 1 = 111
Branch analysis from position: 111
1 jumps found. (Code = 42) Position 1 = 116
Branch analysis from position: 116
Branch analysis from position: 110
1 jumps found. (Code = 42) Position 1 = 116
Branch analysis from position: 116
Branch analysis from position: 115
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 68
Branch analysis from position: 75
Branch analysis from position: 68
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 46
Branch analysis from position: 53
Branch analysis from position: 46
filename:       /in/EX86b
function name:  (null)
number of ops:  117
compiled vars:  !0 = $testArray, !1 = $numRuns, !2 = $start, !3 = $i, !4 = $jsonTime, !5 = $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                                                 
    9     7        INIT_ARRAY                                       ~8      'string', 'string'
   10     8        ADD_ARRAY_ELEMENT                                ~8      1, 'int'
   11     9        ADD_ARRAY_ELEMENT                                ~8      1.1, 'float'
    9    10        ADD_ARRAY_ELEMENT                                ~8      <true>, 'bool'
   13    11        NEW                                              $9      'Datetime'
         12        SEND_VAL_EX                                              'now'
         13        DO_FCALL                                      0          
         14        ADD_ARRAY_ELEMENT                                ~8      $9, 'date'
   15    15        INIT_ARRAY                                       ~11     'string', 'string'
   16    16        ADD_ARRAY_ELEMENT                                ~11     1, 'int'
   17    17        ADD_ARRAY_ELEMENT                                ~11     1.1, 'float'
    9    18        ADD_ARRAY_ELEMENT                                ~11     <true>, 'bool'
   19    19        NEW                                              $12     'Datetime'
         20        SEND_VAL_EX                                              'now'
         21        DO_FCALL                                      0          
         22        ADD_ARRAY_ELEMENT                                ~11     $12, 'date'
   21    23        INIT_ARRAY                                       ~14     'string', 'string'
   22    24        ADD_ARRAY_ELEMENT                                ~14     1, 'int'
   23    25        ADD_ARRAY_ELEMENT                                ~14     1.1, 'float'
    9    26        ADD_ARRAY_ELEMENT                                ~14     <true>, 'bool'
   25    27        NEW                                              $15     'Datetime'
         28        SEND_VAL_EX                                              'now'
         29        DO_FCALL                                      0          
         30        ADD_ARRAY_ELEMENT                                ~14     $15, 'date'
         31        ADD_ARRAY_ELEMENT                                ~11     ~14, 'array'
         32        ADD_ARRAY_ELEMENT                                ~8      ~11, 'array'
   28    33        INIT_FCALL_BY_NAME                                       'fillArray'
         34        SEND_VAL_EX                                              0
         35        SEND_VAL_EX                                              5
         36        DO_FCALL                                      0  $17     
         37        ADD_ARRAY_ELEMENT                                ~8      $17
    8    38        ASSIGN                                                   !0, ~8
   31    39        ASSIGN                                                   !1, 10000000
   33    40        INIT_FCALL                                               'microtime'
         41        SEND_VAL                                                 <true>
         42        DO_ICALL                                         $20     
         43        ASSIGN                                                   !2, $20
   34    44        ASSIGN                                                   !3, 0
         45      > JMP                                                      ->51
   35    46    >   INIT_FCALL                                               'json_encode'
         47        SEND_VAR                                                 !0
         48        DO_ICALL                                                 
   34    49        IS_SMALLER_OR_EQUAL                              ~24     !3, !1
         50        FREE                                                     ~24
         51    >   POST_INC                                         ~25     !3
         52      > JMPNZ                                                    ~25, ->46
   38    53    >   INIT_FCALL                                               'microtime'
         54        SEND_VAL                                                 <true>
         55        DO_ICALL                                         $26     
         56        SUB                                              ~27     $26, !2
         57        ASSIGN                                                   !4, ~27
   39    58        DIV                                              ~29     !4, !1
         59        CONCAT                                           ~30     'JSON+encoded+in+', ~29
         60        CONCAT                                           ~31     ~30, '+seconds%0A'
         61        ECHO                                                     ~31
   42    62        INIT_FCALL                                               'microtime'
         63        SEND_VAL                                                 <true>
         64        DO_ICALL                                         $32     
         65        ASSIGN                                                   !2, $32
   43    66        ASSIGN                                                   !3, 0
         67      > JMP                                                      ->73
   44    68    >   INIT_FCALL                                               'serialize'
         69        SEND_VAR                                                 !0
         70        DO_ICALL                                                 
   43    71        IS_SMALLER_OR_EQUAL                              ~36     !3, !1
         72        FREE                                                     ~36
         73    >   POST_INC                                         ~37     !3
         74      > JMPNZ                                                    ~37, ->68
   47    75    >   INIT_FCALL                                               'microtime'
         76        SEND_VAL                                                 <true>
         77        DO_ICALL                                         $38     
         78        SUB                                              ~39     $38, !2
         79        ASSIGN                                                   !5, ~39
   48    80        DIV                                              ~41     !5, !1
         81        CONCAT                                           ~42     'PHP+serialized+in+', ~41
         82        CONCAT                                           ~43     ~42, '+seconds%0A'
         83        ECHO                                                     ~43
   51    84        IS_SMALLER                                               !4, !5
         85      > JMPZ                                                     ~44, ->97
   53    86    >   INIT_FCALL                                               'number_format'
         87        DIV                                              ~45     !5, !4
         88        SUB                                              ~46     ~45, 1
         89        MUL                                              ~47     ~46, 100
         90        SEND_VAL                                                 ~47
         91        SEND_VAL                                                 2
         92        DO_ICALL                                         $48     
         93        CONCAT                                           ~49     'json_encode%28%29+was+roughly+', $48
         94        CONCAT                                           ~50     ~49, '%25+faster+than+serialize%28%29'
         95        ECHO                                                     ~50
   51    96      > JMP                                                      ->116
   55    97    >   IS_SMALLER                                               !5, !4
         98      > JMPZ                                                     ~51, ->115
   57    99    > > JMPZ                                                     !5, ->110
        100    >   INIT_FCALL                                               'number_format'
        101        DIV                                              ~52     !4, !5
        102        SUB                                              ~53     ~52, 1
        103        MUL                                              ~54     ~53, 100
        104        SEND_VAL                                                 ~54
        105        SEND_VAL                                                 2
        106        DO_ICALL                                         $55     
        107        CONCAT                                           ~56     $55, '%25'
        108        QM_ASSIGN                                        ~57     ~56
        109      > JMP                                                      ->111
        110    >   QM_ASSIGN                                        ~57     'insanely'
        111    >   CONCAT                                           ~58     'serialize%28%29+was+roughly+', ~57
        112        CONCAT                                           ~59     ~58, '+faster+than+json_encode%28%29'
        113        ECHO                                                     ~59
   55   114      > JMP                                                      ->116
   59   115    >   ECHO                                                     'This+is+a+draw'
   79   116    > > 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/EX86b
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
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   64     2        BIND_STATIC                                              !2
   65     3        TYPE_CHECK                                    2          !2
          4      > JMPZ                                                     ~5, ->6
   67     5    >   ASSIGN                                                   !2, <array>
   69     6    >   IS_SMALLER                                               !0, !1
          7      > JMPZ                                                     ~7, ->21
   71     8    >   ASSIGN                                                   !3, <array>
   72     9      > FE_RESET_R                                       $9      !2, ->19
         10    > > FE_FETCH_R                                               $9, !4, ->19
   74    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
   72    18      > JMP                                                      ->10
         19    >   FE_FREE                                                  $9
   76    20      > RETURN                                                   !3
   78    21    > > RETURN                                                   'empty'
   79    22*     > RETURN                                                   null

End of function fillarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.76 ms | 1020 KiB | 20 Q