3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TimeWrapper { private static $now_time = 0; /** * @param bool $force_refresh 是否强制刷新 * @return int */ public static function getTime($force_refresh = false) { if ($force_refresh) { self::$now_time = time(); } else { if (!self::$now_time) { self::$now_time = time(); } } return self::$now_time; } } // Dont' abuse 3v4l $n = 5000; $start = microtime(true); for ($i = 0; $i < $n; $i++) { $t = TimeWrapper::getTime(); } $finish = microtime(true); echo "TimeWrapper: " . ($finish - $start) . PHP_EOL; $start = microtime(true); for ($i = 0; $i < $n; $i++) { $t = time(); } $finish = microtime(true); echo "time: " . ($finish - $start) . PHP_EOL;
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 = 7
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 27
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 27
Branch analysis from position: 33
Branch analysis from position: 27
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 7
Branch analysis from position: 13
Branch analysis from position: 7
filename:       /in/rPU1o
function name:  (null)
number of ops:  42
compiled vars:  !0 = $n, !1 = $start, !2 = $i, !3 = $t, !4 = $finish
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ASSIGN                                                   !0, 5000
   27     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $6      
          4        ASSIGN                                                   !1, $6
   28     5        ASSIGN                                                   !2, 0
          6      > JMP                                                      ->11
   29     7    >   INIT_STATIC_METHOD_CALL                                  'TimeWrapper', 'getTime'
          8        DO_FCALL                                      0  $9      
          9        ASSIGN                                                   !3, $9
   28    10        PRE_INC                                                  !2
         11    >   IS_SMALLER                                               !2, !0
         12      > JMPNZ                                                    ~12, ->7
   31    13    >   INIT_FCALL                                               'microtime'
         14        SEND_VAL                                                 <true>
         15        DO_ICALL                                         $13     
         16        ASSIGN                                                   !4, $13
   32    17        SUB                                              ~15     !4, !1
         18        CONCAT                                           ~16     'TimeWrapper%3A+', ~15
         19        CONCAT                                           ~17     ~16, '%0A'
         20        ECHO                                                     ~17
   35    21        INIT_FCALL                                               'microtime'
         22        SEND_VAL                                                 <true>
         23        DO_ICALL                                         $18     
         24        ASSIGN                                                   !1, $18
   36    25        ASSIGN                                                   !2, 0
         26      > JMP                                                      ->31
   37    27    >   INIT_FCALL                                               'time'
         28        DO_ICALL                                         $21     
         29        ASSIGN                                                   !3, $21
   36    30        PRE_INC                                                  !2
         31    >   IS_SMALLER                                               !2, !0
         32      > JMPNZ                                                    ~24, ->27
   39    33    >   INIT_FCALL                                               'microtime'
         34        SEND_VAL                                                 <true>
         35        DO_ICALL                                         $25     
         36        ASSIGN                                                   !4, $25
   40    37        SUB                                              ~27     !4, !1
         38        CONCAT                                           ~28     'time%3A++++++++', ~27
         39        CONCAT                                           ~29     ~28, '%0A'
         40        ECHO                                                     ~29
   41    41      > RETURN                                                   1

Class TimeWrapper:
Function gettime:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 7
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/rPU1o
function name:  getTime
number of ops:  17
compiled vars:  !0 = $force_refresh
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV_INIT                                        !0      <false>
   13     1      > JMPZ                                                     !0, ->7
   14     2    >   INIT_FCALL                                               'time'
          3        DO_ICALL                                         $2      
          4        ASSIGN_STATIC_PROP                                       'now_time'
          5        OP_DATA                                                  $2
          6      > JMP                                                      ->14
   16     7    >   FETCH_STATIC_PROP_R          unknown             ~3      'now_time'
          8        BOOL_NOT                                         ~4      ~3
          9      > JMPZ                                                     ~4, ->14
   17    10    >   INIT_FCALL                                               'time'
         11        DO_ICALL                                         $6      
         12        ASSIGN_STATIC_PROP                                       'now_time'
         13        OP_DATA                                                  $6
   20    14    >   FETCH_STATIC_PROP_R          unknown             ~7      'now_time'
         15      > RETURN                                                   ~7
   21    16*     > RETURN                                                   null

End of function gettime

End of class TimeWrapper.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.01 ms | 1400 KiB | 17 Q