3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Dont' abuse 3v4l $n = 10000; // 空循环时间 $start = microtime(true); for ($i = 0; $i < $n; $i++) { } $finish = microtime(true); $loop_time = $finish - $start; // 普通 $start = microtime(true); for ($i = 0; $i < $n; $i++) { $t = time(); } $finish = microtime(true); $microtime_time = $finish - $start - $loop_time; echo "microtime: $microtime_time \t100%" . PHP_EOL; // 方式一:通过 PHP 实现,时间缓存在静态变量中 class CacheTime { private static $time = 0; public static function getTime() { return self::$time; } // 需要 timer 定时调用 setTime 更新 public static function setTime() { self::$time = microtime(true); } } $start = microtime(true); for ($i = 0; $i < $n; $i++) { $t = CacheTime::getTime(); } $finish = microtime(true); $class_cache_time = $finish - $start - $loop_time; echo "CacheTime: $class_cache_time \t" . ($class_cache_time / $microtime_time * 100) . '%' . PHP_EOL;; // 方式二:通过扩展实现,时间存在 C 的静态/全局变量中,通过定时器更新 $start = microtime(true); for ($i = 0; $i < $n; $i++) { // gc_enabled 直接取 GC_G(gc_enabled),没有参数,接近时间缓存的实现 $t = gc_enabled(); } $finish = microtime(true); $c_cache_time = $finish - $start - $loop_time; echo "cache_time: $c_cache_time \t" . ($c_cache_time / $microtime_time * 100) . '%' . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 7
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 22
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 46
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
2 jumps found. (Code = 44) Position 1 = 80, Position 2 = 74
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 74
2 jumps found. (Code = 44) Position 1 = 80, Position 2 = 74
Branch analysis from position: 80
Branch analysis from position: 74
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 46
Branch analysis from position: 52
Branch analysis from position: 46
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 22
Branch analysis from position: 28
Branch analysis from position: 22
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 7
Branch analysis from position: 10
Branch analysis from position: 7
filename:       /in/HEXFF
function name:  (null)
number of ops:  97
compiled vars:  !0 = $n, !1 = $start, !2 = $i, !3 = $finish, !4 = $loop_time, !5 = $t, !6 = $microtime_time, !7 = $class_cache_time, !8 = $c_cache_time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, 10000
    7     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $10     
          4        ASSIGN                                                   !1, $10
    8     5        ASSIGN                                                   !2, 0
          6      > JMP                                                      ->8
          7    >   PRE_INC                                                  !2
          8    >   IS_SMALLER                                               !2, !0
          9      > JMPNZ                                                    ~14, ->7
   11    10    >   INIT_FCALL                                               'microtime'
         11        SEND_VAL                                                 <true>
         12        DO_ICALL                                         $15     
         13        ASSIGN                                                   !3, $15
   12    14        SUB                                              ~17     !3, !1
         15        ASSIGN                                                   !4, ~17
   15    16        INIT_FCALL                                               'microtime'
         17        SEND_VAL                                                 <true>
         18        DO_ICALL                                         $19     
         19        ASSIGN                                                   !1, $19
   16    20        ASSIGN                                                   !2, 0
         21      > JMP                                                      ->26
   17    22    >   INIT_FCALL                                               'time'
         23        DO_ICALL                                         $22     
         24        ASSIGN                                                   !5, $22
   16    25        PRE_INC                                                  !2
         26    >   IS_SMALLER                                               !2, !0
         27      > JMPNZ                                                    ~25, ->22
   19    28    >   INIT_FCALL                                               'microtime'
         29        SEND_VAL                                                 <true>
         30        DO_ICALL                                         $26     
         31        ASSIGN                                                   !3, $26
   20    32        SUB                                              ~28     !3, !1
         33        SUB                                              ~29     ~28, !4
         34        ASSIGN                                                   !6, ~29
   21    35        ROPE_INIT                                     3  ~32     'microtime%3A++'
         36        ROPE_ADD                                      1  ~32     ~32, !6
         37        ROPE_END                                      2  ~31     ~32, '+%09100%25'
         38        CONCAT                                           ~34     ~31, '%0A'
         39        ECHO                                                     ~34
   39    40        INIT_FCALL                                               'microtime'
         41        SEND_VAL                                                 <true>
         42        DO_ICALL                                         $35     
         43        ASSIGN                                                   !1, $35
   40    44        ASSIGN                                                   !2, 0
         45      > JMP                                                      ->50
   41    46    >   INIT_STATIC_METHOD_CALL                                  'CacheTime', 'getTime'
         47        DO_FCALL                                      0  $38     
         48        ASSIGN                                                   !5, $38
   40    49        PRE_INC                                                  !2
         50    >   IS_SMALLER                                               !2, !0
         51      > JMPNZ                                                    ~41, ->46
   43    52    >   INIT_FCALL                                               'microtime'
         53        SEND_VAL                                                 <true>
         54        DO_ICALL                                         $42     
         55        ASSIGN                                                   !3, $42
   44    56        SUB                                              ~44     !3, !1
         57        SUB                                              ~45     ~44, !4
         58        ASSIGN                                                   !7, ~45
   45    59        ROPE_INIT                                     3  ~48     'CacheTime%3A++'
         60        ROPE_ADD                                      1  ~48     ~48, !7
         61        ROPE_END                                      2  ~47     ~48, '+%09'
         62        DIV                                              ~50     !7, !6
         63        MUL                                              ~51     ~50, 100
         64        CONCAT                                           ~52     ~47, ~51
         65        CONCAT                                           ~53     ~52, '%25'
         66        CONCAT                                           ~54     ~53, '%0A'
         67        ECHO                                                     ~54
   48    68        INIT_FCALL                                               'microtime'
         69        SEND_VAL                                                 <true>
         70        DO_ICALL                                         $55     
         71        ASSIGN                                                   !1, $55
   49    72        ASSIGN                                                   !2, 0
         73      > JMP                                                      ->78
   51    74    >   INIT_FCALL                                               'gc_enabled'
         75        DO_ICALL                                         $58     
         76        ASSIGN                                                   !5, $58
   49    77        PRE_INC                                                  !2
         78    >   IS_SMALLER                                               !2, !0
         79      > JMPNZ                                                    ~61, ->74
   53    80    >   INIT_FCALL                                               'microtime'
         81        SEND_VAL                                                 <true>
         82        DO_ICALL                                         $62     
         83        ASSIGN                                                   !3, $62
   54    84        SUB                                              ~64     !3, !1
         85        SUB                                              ~65     ~64, !4
         86        ASSIGN                                                   !8, ~65
   55    87        ROPE_INIT                                     3  ~68     'cache_time%3A+'
         88        ROPE_ADD                                      1  ~68     ~68, !8
         89        ROPE_END                                      2  ~67     ~68, '+%09'
         90        DIV                                              ~70     !8, !6
         91        MUL                                              ~71     ~70, 100
         92        CONCAT                                           ~72     ~67, ~71
         93        CONCAT                                           ~73     ~72, '%25'
         94        CONCAT                                           ~74     ~73, '%0A'
         95        ECHO                                                     ~74
   56    96      > RETURN                                                   1

Class CacheTime:
Function gettime:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HEXFF
function name:  getTime
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'time'
          1      > RETURN                                                   ~0
   31     2*     > RETURN                                                   null

End of function gettime

Function settime:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HEXFF
function name:  setTime
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   INIT_FCALL                                               'microtime'
          1        SEND_VAL                                                 <true>
          2        DO_ICALL                                         $1      
          3        ASSIGN_STATIC_PROP                                       'time'
          4        OP_DATA                                                  $1
   37     5      > RETURN                                                   null

End of function settime

End of class CacheTime.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.85 ms | 1456 KiB | 16 Q