3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** strrev function implementation taken from ext/standard/string.c PHP-5-5 branch http://lxr.php.net/xref/PHP_5_5/ext/standard/string.c#3165 // {{{ proto string strrev(string str) // Reverse a string PHP_FUNCTION(strrev) { char *str; char *e, *n, *p; int str_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { return; } n = emalloc(str_len+1); p = n; e = str + str_len; while (--e>=str) { *p++ = *e; } *p = '\0'; RETVAL_STRINGL(n, str_len, 0); } // }}} */ // PHP Implementation function userland_strrev($string) { if (!is_string($string)) { return false; } $new_string = ""; $len = strlen($string); while (--$len > -1) { $new_string .= $string[$len]; } return $new_string; } $string = "Hello PHP!"; $c = 1000; $results = array(); $tests = array('strrev', 'userland_strrev'); foreach ($tests as $test) { for ($i = 0; $i < $c; $i++) { $t = microtime(true); $test($string); $results[$test][] = microtime(true) - $t; } $avg = array_sum($results[$test]) / count($results[$test]); printf("Average cost for function $test: %.6f ms\n", $avg); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 41
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 41
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 8
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 8
Branch analysis from position: 25
Branch analysis from position: 8
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/jaWNQ
function name:  (null)
number of ops:  43
compiled vars:  !0 = $string, !1 = $c, !2 = $results, !3 = $tests, !4 = $test, !5 = $i, !6 = $t, !7 = $avg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   ASSIGN                                                   !0, 'Hello+PHP%21'
   51     1        ASSIGN                                                   !1, 1000
   52     2        ASSIGN                                                   !2, <array>
   53     3        ASSIGN                                                   !3, <array>
   55     4      > FE_RESET_R                                       $12     !3, ->41
          5    > > FE_FETCH_R                                               $12, !4, ->41
   57     6    >   ASSIGN                                                   !5, 0
          7      > JMP                                                      ->23
   58     8    >   INIT_FCALL                                               'microtime'
          9        SEND_VAL                                                 <true>
         10        DO_ICALL                                         $14     
         11        ASSIGN                                                   !6, $14
   59    12        INIT_DYNAMIC_CALL                                        !4
         13        SEND_VAR_EX                                              !0
         14        DO_FCALL                                      0          
   60    15        INIT_FCALL                                               'microtime'
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $19     
         18        SUB                                              ~20     $19, !6
         19        FETCH_DIM_W                                      $17     !2, !4
         20        ASSIGN_DIM                                               $17
         21        OP_DATA                                                  ~20
   57    22        PRE_INC                                                  !5
         23    >   IS_SMALLER                                               !5, !1
         24      > JMPNZ                                                    ~22, ->8
   62    25    >   INIT_FCALL                                               'array_sum'
         26        FETCH_DIM_R                                      ~23     !2, !4
         27        SEND_VAL                                                 ~23
         28        DO_ICALL                                         $24     
         29        FETCH_DIM_R                                      ~25     !2, !4
         30        COUNT                                            ~26     ~25
         31        DIV                                              ~27     $24, ~26
         32        ASSIGN                                                   !7, ~27
   63    33        INIT_FCALL                                               'printf'
         34        ROPE_INIT                                     3  ~30     'Average+cost+for+function+'
         35        ROPE_ADD                                      1  ~30     ~30, !4
         36        ROPE_END                                      2  ~29     ~30, '%3A+%25.6f+ms%0A'
         37        SEND_VAL                                                 ~29
         38        SEND_VAR                                                 !7
         39        DO_ICALL                                                 
   55    40      > JMP                                                      ->5
         41    >   FE_FREE                                                  $12
   64    42      > RETURN                                                   1

Function userland_strrev:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 9
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 9
Branch analysis from position: 14
Branch analysis from position: 9
filename:       /in/jaWNQ
function name:  userland_strrev
number of ops:  16
compiled vars:  !0 = $string, !1 = $new_string, !2 = $len
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        TYPE_CHECK                                   64  ~3      !0
          2        BOOL_NOT                                         ~4      ~3
          3      > JMPZ                                                     ~4, ->5
   37     4    > > RETURN                                                   <false>
   40     5    >   ASSIGN                                                   !1, ''
   41     6        STRLEN                                           ~6      !0
          7        ASSIGN                                                   !2, ~6
   43     8      > JMP                                                      ->11
   44     9    >   FETCH_DIM_R                                      ~8      !0, !2
         10        ASSIGN_OP                                     8          !1, ~8
   43    11    >   PRE_DEC                                          ~10     !2
         12        IS_SMALLER                                               -1, ~10
         13      > JMPNZ                                                    ~11, ->9
   47    14    > > RETURN                                                   !1
   48    15*     > RETURN                                                   null

End of function userland_strrev

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.49 ms | 1400 KiB | 19 Q