3v4l.org

run code in 300+ PHP versions simultaneously
<?php function acceptOne($a) {}; $str = str_repeat('abcd', 64 * 1024); // 256 KiB length $benchFx = function (string $msg, \Closure $fx) { $times = []; for ($i = 0; $i < 10; $i++) { $t = microtime(true); $fx(); $t = microtime(true) - $t; $times[] = $t; } $bestTime = min($times); echo $msg . ': ' . round($bestTime * 1000, 2) . " ms\n"; }; $benchFx('json_encode', function () use ($str) { for ($i = 0; $i < 200; $i++) { $res = json_encode($str); acceptOne($res); } }); $benchFx('serialize', function () use ($str) { for ($i = 0; $i < 200; $i++) { $res = serialize($str); acceptOne($res); } });
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XeJTn
function name:  (null)
number of ops:  20
compiled vars:  !0 = $str, !1 = $benchFx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   INIT_FCALL                                               'str_repeat'
          1        SEND_VAL                                                 'abcd'
          2        SEND_VAL                                                 65536
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
    7     5        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
          6        ASSIGN                                                   !1, ~4
   20     7        INIT_DYNAMIC_CALL                                        !1
          8        SEND_VAL_EX                                              'json_encode'
          9        DECLARE_LAMBDA_FUNCTION                          ~6      [1]
         10        BIND_LEXICAL                                             ~6, !0
   25    11        SEND_VAL_EX                                              ~6
   20    12        DO_FCALL                                      0          
   27    13        INIT_DYNAMIC_CALL                                        !1
         14        SEND_VAL_EX                                              'serialize'
         15        DECLARE_LAMBDA_FUNCTION                          ~8      [2]
         16        BIND_LEXICAL                                             ~8, !0
   32    17        SEND_VAL_EX                                              ~8
   27    18        DO_FCALL                                      0          
   32    19      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 5
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 5
Branch analysis from position: 21
Branch analysis from position: 5
filename:       /in/XeJTn
function name:  {closure}
number of ops:  35
compiled vars:  !0 = $msg, !1 = $fx, !2 = $times, !3 = $i, !4 = $t, !5 = $bestTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        ASSIGN                                                   !2, <array>
    9     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->19
   10     5    >   INIT_FCALL                                               'microtime'
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !4, $8
   11     9        INIT_DYNAMIC_CALL                                        !1
         10        DO_FCALL                                      0          
   12    11        INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $11     
         14        SUB                                              ~12     $11, !4
         15        ASSIGN                                                   !4, ~12
   13    16        ASSIGN_DIM                                               !2
         17        OP_DATA                                                  !4
    9    18        PRE_INC                                                  !3
         19    >   IS_SMALLER                                               !3, 10
         20      > JMPNZ                                                    ~16, ->5
   16    21    >   INIT_FCALL                                               'min'
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                         $17     
         24        ASSIGN                                                   !5, $17
   17    25        CONCAT                                           ~19     !0, '%3A+'
         26        INIT_FCALL                                               'round'
         27        MUL                                              ~20     !5, 1000
         28        SEND_VAL                                                 ~20
         29        SEND_VAL                                                 2
         30        DO_ICALL                                         $21     
         31        CONCAT                                           ~22     ~19, $21
         32        CONCAT                                           ~23     ~22, '+ms%0A'
         33        ECHO                                                     ~23
   18    34      > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 3
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 3
Branch analysis from position: 13
Branch analysis from position: 3
filename:       /in/XeJTn
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $str, !1 = $i, !2 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   BIND_STATIC                                              !0
   21     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->11
   22     3    >   INIT_FCALL                                               'json_encode'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $4      
          6        ASSIGN                                                   !2, $4
   23     7        INIT_FCALL                                               'acceptone'
          8        SEND_VAR                                                 !2
          9        DO_FCALL                                      0          
   21    10        PRE_INC                                                  !1
         11    >   IS_SMALLER                                               !1, 200
         12      > JMPNZ                                                    ~8, ->3
   25    13    > > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 3
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 3
Branch analysis from position: 13
Branch analysis from position: 3
filename:       /in/XeJTn
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $str, !1 = $i, !2 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   BIND_STATIC                                              !0
   28     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->11
   29     3    >   INIT_FCALL                                               'serialize'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $4      
          6        ASSIGN                                                   !2, $4
   30     7        INIT_FCALL                                               'acceptone'
          8        SEND_VAR                                                 !2
          9        DO_FCALL                                      0          
   28    10        PRE_INC                                                  !1
         11    >   IS_SMALLER                                               !1, 200
         12      > JMPNZ                                                    ~8, ->3
   32    13    > > RETURN                                                   null

End of Dynamic Function 2

Function acceptone:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XeJTn
function name:  acceptOne
number of ops:  2
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function acceptone

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.9 ms | 1017 KiB | 21 Q