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 = 40
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 40
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 8
Branch analysis from position: 24
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 = 24, Position 2 = 8
Branch analysis from position: 24
Branch analysis from position: 8
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/fCTge
function name:  (null)
number of ops:  42
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, ->40
          5    > > FE_FETCH_R                                               $12, !4, ->40
   57     6    >   ASSIGN                                                   !5, 0
          7      > JMP                                                      ->22
   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                                         $18     
         18        SUB                                              ~19     $18, !6
         19        ASSIGN_DIM                                               !2, !4
         20        OP_DATA                                                  ~19
   57    21        PRE_INC                                                  !5
         22    >   IS_SMALLER                                               !5, !1
         23      > JMPNZ                                                    ~21, ->8
   62    24    >   INIT_FCALL                                               'array_sum'
         25        FETCH_DIM_R                                      ~22     !2, !4
         26        SEND_VAL                                                 ~22
         27        DO_ICALL                                         $23     
         28        FETCH_DIM_R                                      ~24     !2, !4
         29        COUNT                                            ~25     ~24
         30        DIV                                              ~26     $23, ~25
         31        ASSIGN                                                   !7, ~26
   63    32        INIT_FCALL                                               'printf'
         33        ROPE_INIT                                     3  ~29     'Average+cost+for+function+'
         34        ROPE_ADD                                      1  ~29     ~29, !4
         35        ROPE_END                                      2  ~28     ~29, '%3A+%25.6f+ms%0A'
         36        SEND_VAL                                                 ~28
         37        SEND_VAR                                                 !7
         38        DO_ICALL                                                 
   55    39      > JMP                                                      ->5
         40    >   FE_FREE                                                  $12
   64    41      > 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/fCTge
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:
154.39 ms | 1400 KiB | 19 Q