3v4l.org

run code in 300+ PHP versions simultaneously
<?php $num_cycles = 1000000; $src = 'path/to.a/fonts/folder/in.a/themes/some.font.woff'; $sec_to_microsec = 1000000.0; // Code implementations to benchmark. function using_explode_and_end() { global $src; $src_as_array = explode( '.', $src ); $file_type = end( $src_as_array ); } function using_pos_and_substring() { global $src; $file_type_pos = strrpos( $src, '.' ) + 1; $file_type = substr( $src, $file_type_pos ); } /** * BENCHMARK CODE */ printf( "Average microseconds running code for %s cycles:\n\n", number_format( $num_cycles, 0 ) ); // Benchmark the code with `explode` and `end` combination. $microseconds = 0; $start_time = microtime( true ); for ( $i = 1; $i <= $num_cycles; $i++ ) { using_explode_and_end(); } $end_time = microtime( true ); $microseconds += ( $end_time - $start_time ) * $sec_to_microsec; // store in microseconds. printf( "`explode` with `end`: \t\t%s μs\n", number_format( $microseconds / $num_cycles, 4 ) ); // Benchmark the code with `explode` and `end` combination. $microseconds = 0; $start_time = microtime( true ); for ( $i = 1; $i <= $num_cycles; $i++ ) { using_pos_and_substring(); } $end_time = microtime( true ); $microseconds += ( $end_time - $start_time ) * $sec_to_microsec; // store in microseconds. printf( "`strrpos` with `substr`: \t%s μs", number_format( $microseconds / $num_cycles, 4 ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 18
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 51, Position 2 = 46
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 51, Position 2 = 46
Branch analysis from position: 51
Branch analysis from position: 46
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 18
Branch analysis from position: 23
Branch analysis from position: 18
filename:       /in/EnOB1
function name:  (null)
number of ops:  68
compiled vars:  !0 = $num_cycles, !1 = $src, !2 = $sec_to_microsec, !3 = $microseconds, !4 = $start_time, !5 = $i, !6 = $end_time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, 1000000
    5     1        ASSIGN                                                   !1, 'path%2Fto.a%2Ffonts%2Ffolder%2Fin.a%2Fthemes%2Fsome.font.woff'
    6     2        ASSIGN                                                   !2, 1.0e+6
   28     3        INIT_FCALL                                               'printf'
          4        SEND_VAL                                                 'Average+microseconds+running+code+for+%25s+cycles%3A%0A%0A'
          5        INIT_FCALL                                               'number_format'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 0
          8        DO_ICALL                                         $10     
          9        SEND_VAR                                                 $10
         10        DO_ICALL                                                 
   31    11        ASSIGN                                                   !3, 0
   32    12        INIT_FCALL                                               'microtime'
         13        SEND_VAL                                                 <true>
         14        DO_ICALL                                         $13     
         15        ASSIGN                                                   !4, $13
   33    16        ASSIGN                                                   !5, 1
         17      > JMP                                                      ->21
   34    18    >   INIT_FCALL                                               'using_explode_and_end'
         19        DO_FCALL                                      0          
   33    20        PRE_INC                                                  !5
         21    >   IS_SMALLER_OR_EQUAL                                      !5, !0
         22      > JMPNZ                                                    ~18, ->18
   36    23    >   INIT_FCALL                                               'microtime'
         24        SEND_VAL                                                 <true>
         25        DO_ICALL                                         $19     
         26        ASSIGN                                                   !6, $19
   37    27        SUB                                              ~21     !6, !4
         28        MUL                                              ~22     !2, ~21
         29        ASSIGN_OP                                     1          !3, ~22
   38    30        INIT_FCALL                                               'printf'
         31        SEND_VAL                                                 '%60explode%60+with+%60end%60%3A+%09%09%25s+%CE%BCs%0A'
         32        INIT_FCALL                                               'number_format'
         33        DIV                                              ~24     !3, !0
         34        SEND_VAL                                                 ~24
         35        SEND_VAL                                                 4
         36        DO_ICALL                                         $25     
         37        SEND_VAR                                                 $25
         38        DO_ICALL                                                 
   42    39        ASSIGN                                                   !3, 0
   43    40        INIT_FCALL                                               'microtime'
         41        SEND_VAL                                                 <true>
         42        DO_ICALL                                         $28     
         43        ASSIGN                                                   !4, $28
   44    44        ASSIGN                                                   !5, 1
         45      > JMP                                                      ->49
   45    46    >   INIT_FCALL                                               'using_pos_and_substring'
         47        DO_FCALL                                      0          
   44    48        PRE_INC                                                  !5
         49    >   IS_SMALLER_OR_EQUAL                                      !5, !0
         50      > JMPNZ                                                    ~33, ->46
   47    51    >   INIT_FCALL                                               'microtime'
         52        SEND_VAL                                                 <true>
         53        DO_ICALL                                         $34     
         54        ASSIGN                                                   !6, $34
   48    55        SUB                                              ~36     !6, !4
         56        MUL                                              ~37     !2, ~36
         57        ASSIGN_OP                                     1          !3, ~37
   49    58        INIT_FCALL                                               'printf'
         59        SEND_VAL                                                 '%60strrpos%60+with+%60substr%60%3A+%09%25s+%CE%BCs'
         60        INIT_FCALL                                               'number_format'
         61        DIV                                              ~39     !3, !0
         62        SEND_VAL                                                 ~39
         63        SEND_VAL                                                 4
         64        DO_ICALL                                         $40     
         65        SEND_VAR                                                 $40
         66        DO_ICALL                                                 
         67      > RETURN                                                   1

Function using_explode_and_end:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EnOB1
function name:  using_explode_and_end
number of ops:  11
compiled vars:  !0 = $src, !1 = $src_as_array, !2 = $file_type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   BIND_GLOBAL                                              !0, 'src'
   13     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '.'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
   14     6        INIT_FCALL                                               'end'
          7        SEND_REF                                                 !1
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !2, $5
   15    10      > RETURN                                                   null

End of function using_explode_and_end

Function using_pos_and_substring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EnOB1
function name:  using_pos_and_substring
number of ops:  13
compiled vars:  !0 = $src, !1 = $file_type_pos, !2 = $file_type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   BIND_GLOBAL                                              !0, 'src'
   19     1        INIT_FCALL                                               'strrpos'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '.'
          4        DO_ICALL                                         $3      
          5        ADD                                              ~4      $3, 1
          6        ASSIGN                                                   !1, ~4
   20     7        INIT_FCALL                                               'substr'
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $6      
         11        ASSIGN                                                   !2, $6
   21    12      > RETURN                                                   null

End of function using_pos_and_substring

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.32 ms | 1028 KiB | 22 Q