3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TestFixedArray extends SplFixedArray { private $_elements; public function __sleep() { $arr = (array)$this; unset($arr["\0TestFixedArray\0_elements"]); $this->_elements = $arr; $this->setSize(0); $arr = null; return array('_elements'); } public function __wakeup() { $size = count($this->_elements); $this->setSize($size); for($i = 0; $i < $size; $i++) { $this[(int)$i] = (int)$this->_elements[$i]; } $this->_elements = null; unset($this->_elements); } } $n = 100000; $t = microtime(true); $m = memory_get_usage(true); if(file_exists('cache.txt')) { echo 'Unserialize' . PHP_EOL; $content = file_get_contents('cache.txt'); $a = igbinary_unserialize($content); //$a = unserialize($content); $content = null; } else { echo 'Serialize' . PHP_EOL; //$a = new SplFixedArray($n); $a = new TestFixedArray($n); //$a = array(); for($i = 0; $i < $n; $i++) { $a[(int)$i] = (int)$i; } if(!file_exists('cache.txt')) { var_dump('serialize'); //file_put_contents('cache.txt', serialize($a)); file_put_contents('cache.txt', igbinary_serialize($a)); } } echo 'Peak: ' . memory_get_peak_usage(true) . PHP_EOL; echo 'Usage: ' . (memory_get_usage(true) - $m) . PHP_EOL; echo 'Time: ' . (microtime(true) - $t) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 24
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 31
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 53
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 31
Branch analysis from position: 38
Branch analysis from position: 31
filename:       /in/1Oomf
function name:  (null)
number of ops:  74
compiled vars:  !0 = $n, !1 = $t, !2 = $m, !3 = $content, !4 = $a, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   ASSIGN                                                   !0, 100000
   31     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $7      
          4        ASSIGN                                                   !1, $7
   32     5        INIT_FCALL                                               'memory_get_usage'
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $9      
          8        ASSIGN                                                   !2, $9
   34     9        INIT_FCALL                                               'file_exists'
         10        SEND_VAL                                                 'cache.txt'
         11        DO_ICALL                                         $11     
         12      > JMPZ                                                     $11, ->24
   35    13    >   ECHO                                                     'Unserialize%0A'
   37    14        INIT_FCALL                                               'file_get_contents'
         15        SEND_VAL                                                 'cache.txt'
         16        DO_ICALL                                         $12     
         17        ASSIGN                                                   !3, $12
   38    18        INIT_FCALL_BY_NAME                                       'igbinary_unserialize'
         19        SEND_VAR_EX                                              !3
         20        DO_FCALL                                      0  $14     
         21        ASSIGN                                                   !4, $14
   40    22        ASSIGN                                                   !3, null
   34    23      > JMP                                                      ->53
   42    24    >   ECHO                                                     'Serialize%0A'
   45    25        NEW                                              $17     'TestFixedArray'
         26        SEND_VAR_EX                                              !0
         27        DO_FCALL                                      0          
         28        ASSIGN                                                   !4, $17
   47    29        ASSIGN                                                   !5, 0
         30      > JMP                                                      ->36
   48    31    >   CAST                                          4  ~21     !5
         32        CAST                                          4  ~23     !5
         33        ASSIGN_DIM                                               !4, ~21
         34        OP_DATA                                                  ~23
   47    35        PRE_INC                                                  !5
         36    >   IS_SMALLER                                               !5, !0
         37      > JMPNZ                                                    ~25, ->31
   51    38    >   INIT_FCALL                                               'file_exists'
         39        SEND_VAL                                                 'cache.txt'
         40        DO_ICALL                                         $26     
         41        BOOL_NOT                                         ~27     $26
         42      > JMPZ                                                     ~27, ->53
   52    43    >   INIT_FCALL                                               'var_dump'
         44        SEND_VAL                                                 'serialize'
         45        DO_ICALL                                                 
   54    46        INIT_FCALL                                               'file_put_contents'
         47        SEND_VAL                                                 'cache.txt'
         48        INIT_FCALL_BY_NAME                                       'igbinary_serialize'
         49        SEND_VAR_EX                                              !4
         50        DO_FCALL                                      0  $29     
         51        SEND_VAR                                                 $29
         52        DO_ICALL                                                 
   58    53    >   INIT_FCALL                                               'memory_get_peak_usage'
         54        SEND_VAL                                                 <true>
         55        DO_ICALL                                         $31     
         56        CONCAT                                           ~32     'Peak%3A+', $31
         57        CONCAT                                           ~33     ~32, '%0A'
         58        ECHO                                                     ~33
   59    59        INIT_FCALL                                               'memory_get_usage'
         60        SEND_VAL                                                 <true>
         61        DO_ICALL                                         $34     
         62        SUB                                              ~35     $34, !2
         63        CONCAT                                           ~36     'Usage%3A+', ~35
         64        CONCAT                                           ~37     ~36, '%0A'
         65        ECHO                                                     ~37
   60    66        INIT_FCALL                                               'microtime'
         67        SEND_VAL                                                 <true>
         68        DO_ICALL                                         $38     
         69        SUB                                              ~39     $38, !1
         70        CONCAT                                           ~40     'Time%3A+', ~39
         71        CONCAT                                           ~41     ~40, '%0A'
         72        ECHO                                                     ~41
         73      > RETURN                                                   1

Class TestFixedArray:
Function __sleep:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1Oomf
function name:  __sleep
number of ops:  12
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   FETCH_THIS                                       ~1      
          1        CAST                                          7  ~2      ~1
          2        ASSIGN                                                   !0, ~2
   10     3        UNSET_DIM                                                !0, '%00TestFixedArray%00_elements'
   11     4        ASSIGN_OBJ                                               '_elements'
          5        OP_DATA                                                  !0
   12     6        INIT_METHOD_CALL                                         'setSize'
          7        SEND_VAL_EX                                              0
          8        DO_FCALL                                      0          
   13     9        ASSIGN                                                   !0, null
   15    10      > RETURN                                                   <array>
   16    11*     > RETURN                                                   null

End of function __sleep

Function __wakeup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 8
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 8
Branch analysis from position: 18
Branch analysis from position: 8
filename:       /in/1Oomf
function name:  __wakeup
number of ops:  22
compiled vars:  !0 = $size, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   FETCH_OBJ_R                                      ~2      '_elements'
          1        COUNT                                            ~3      ~2
          2        ASSIGN                                                   !0, ~3
   21     3        INIT_METHOD_CALL                                         'setSize'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
   22     6        ASSIGN                                                   !1, 0
          7      > JMP                                                      ->16
   23     8    >   FETCH_THIS                                       $7      
          9        CAST                                          4  ~8      !1
         10        FETCH_OBJ_R                                      ~10     '_elements'
         11        FETCH_DIM_R                                      ~11     ~10, !1
         12        CAST                                          4  ~12     ~11
         13        ASSIGN_DIM                                               $7, ~8
         14        OP_DATA                                                  ~12
   22    15        PRE_INC                                                  !1
         16    >   IS_SMALLER                                               !1, !0
         17      > JMPNZ                                                    ~14, ->8
   25    18    >   ASSIGN_OBJ                                               '_elements'
         19        OP_DATA                                                  null
   26    20        UNSET_OBJ                                                '_elements'
   27    21      > RETURN                                                   null

End of function __wakeup

End of class TestFixedArray.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.33 ms | 1026 KiB | 20 Q