3v4l.org

run code in 300+ PHP versions simultaneously
<?php function convertNew($input) { $oldMin = 0; $oldMax = 1; $newMin = 127; $newMax = 0; return ceil(((($input- $oldMin) * ($newMax - $newMin)) / ($oldMax - $oldMin)) + $newMin); } function convertOld($input) { $range_input = range(1, 0, 1/127); $range_output = range(0, 127); foreach ($range_input as $key => $value) { if ($value <= $input) { return $range_output[$key]; } } return 127; } // Simple benchmark for OLD alpha2gd conversion $start = microtime(1); foreach (range(0,1,1/1000) as $input) { convertOld($input); } $diffOld = microtime(1) - $start; echo "Old time: $diffOld\n"; // Simple benchmark for NEW alpha2gd conversion $start = microtime(1); foreach (range(0,1,1/1000) as $input) { convertNew($input); } $diffNew = microtime(1) - $start; echo "New time: $diffNew\n"; echo ($diffNew/$diffOld*100)."% faster\n"; // Iterate through a whole bunch of floats $warnings = array(); foreach (range(0,1,1/10000) as $input) { if (convertOld($input) != convertNew($input)) $warnings[] = $input; } if (count($warnings)) { echo "Warning, value mismatches at ".implode(", ", $warnings)."\n"; } else { echo "All values passed!\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 15
2 jumps found. (Code = 77) Position 1 = 35, Position 2 = 40
Branch analysis from position: 35
2 jumps found. (Code = 78) Position 1 = 36, Position 2 = 40
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 40
2 jumps found. (Code = 77) Position 1 = 61, Position 2 = 73
Branch analysis from position: 61
2 jumps found. (Code = 78) Position 1 = 62, Position 2 = 73
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 72
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
Branch analysis from position: 72
Branch analysis from position: 73
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 84
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 84
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 73
Branch analysis from position: 40
Branch analysis from position: 15
filename:       /in/lKdPn
function name:  (null)
number of ops:  86
compiled vars:  !0 = $start, !1 = $input, !2 = $diffOld, !3 = $diffNew, !4 = $warnings
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'microtime'
          1        SEND_VAL                                                 1
          2        DO_ICALL                                         $5      
          3        ASSIGN                                                   !0, $5
   29     4        INIT_FCALL                                               'range'
          5        SEND_VAL                                                 0
          6        SEND_VAL                                                 1
          7        SEND_VAL                                                 0.001
          8        DO_ICALL                                         $7      
          9      > FE_RESET_R                                       $8      $7, ->15
         10    > > FE_FETCH_R                                               $8, !1, ->15
         11    >   INIT_FCALL                                               'convertold'
         12        SEND_VAR                                                 !1
         13        DO_FCALL                                      0          
         14      > JMP                                                      ->10
         15    >   FE_FREE                                                  $8
   30    16        INIT_FCALL                                               'microtime'
         17        SEND_VAL                                                 1
         18        DO_ICALL                                         $10     
         19        SUB                                              ~11     $10, !0
         20        ASSIGN                                                   !2, ~11
   31    21        ROPE_INIT                                     3  ~14     'Old+time%3A+'
         22        ROPE_ADD                                      1  ~14     ~14, !2
         23        ROPE_END                                      2  ~13     ~14, '%0A'
         24        ECHO                                                     ~13
   34    25        INIT_FCALL                                               'microtime'
         26        SEND_VAL                                                 1
         27        DO_ICALL                                         $16     
         28        ASSIGN                                                   !0, $16
   35    29        INIT_FCALL                                               'range'
         30        SEND_VAL                                                 0
         31        SEND_VAL                                                 1
         32        SEND_VAL                                                 0.001
         33        DO_ICALL                                         $18     
         34      > FE_RESET_R                                       $19     $18, ->40
         35    > > FE_FETCH_R                                               $19, !1, ->40
         36    >   INIT_FCALL                                               'convertnew'
         37        SEND_VAR                                                 !1
         38        DO_FCALL                                      0          
         39      > JMP                                                      ->35
         40    >   FE_FREE                                                  $19
   36    41        INIT_FCALL                                               'microtime'
         42        SEND_VAL                                                 1
         43        DO_ICALL                                         $21     
         44        SUB                                              ~22     $21, !0
         45        ASSIGN                                                   !3, ~22
   37    46        ROPE_INIT                                     3  ~25     'New+time%3A+'
         47        ROPE_ADD                                      1  ~25     ~25, !3
         48        ROPE_END                                      2  ~24     ~25, '%0A'
         49        ECHO                                                     ~24
   39    50        DIV                                              ~27     !3, !2
         51        MUL                                              ~28     ~27, 100
         52        CONCAT                                           ~29     ~28, '%25+faster%0A'
         53        ECHO                                                     ~29
   42    54        ASSIGN                                                   !4, <array>
   43    55        INIT_FCALL                                               'range'
         56        SEND_VAL                                                 0
         57        SEND_VAL                                                 1
         58        SEND_VAL                                                 0.0001
         59        DO_ICALL                                         $31     
         60      > FE_RESET_R                                       $32     $31, ->73
         61    > > FE_FETCH_R                                               $32, !1, ->73
   44    62    >   INIT_FCALL                                               'convertold'
         63        SEND_VAR                                                 !1
         64        DO_FCALL                                      0  $33     
         65        INIT_FCALL                                               'convertnew'
         66        SEND_VAR                                                 !1
         67        DO_FCALL                                      0  $34     
         68        IS_NOT_EQUAL                                             $33, $34
         69      > JMPZ                                                     ~35, ->72
         70    >   ASSIGN_DIM                                               !4
         71        OP_DATA                                                  !1
   43    72    > > JMP                                                      ->61
         73    >   FE_FREE                                                  $32
   46    74        COUNT                                            ~37     !4
         75      > JMPZ                                                     ~37, ->84
   47    76    >   INIT_FCALL                                               'implode'
         77        SEND_VAL                                                 '%2C+'
         78        SEND_VAR                                                 !4
         79        DO_ICALL                                         $38     
         80        CONCAT                                           ~39     'Warning%2C+value+mismatches+at+', $38
         81        CONCAT                                           ~40     ~39, '%0A'
         82        ECHO                                                     ~40
         83      > JMP                                                      ->85
   49    84    >   ECHO                                                     'All+values+passed%21%0A'
   50    85    > > RETURN                                                   1

Function convertnew:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lKdPn
function name:  convertNew
number of ops:  16
compiled vars:  !0 = $input, !1 = $oldMin, !2 = $oldMax, !3 = $newMin, !4 = $newMax
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, 0
    6     2        ASSIGN                                                   !2, 1
    7     3        ASSIGN                                                   !3, 127
    8     4        ASSIGN                                                   !4, 0
   10     5        INIT_FCALL                                               'ceil'
          6        SUB                                              ~9      !0, !1
          7        SUB                                              ~10     !4, !3
          8        MUL                                              ~11     ~9, ~10
          9        SUB                                              ~12     !2, !1
         10        DIV                                              ~13     ~11, ~12
         11        ADD                                              ~14     ~13, !3
         12        SEND_VAL                                                 ~14
         13        DO_ICALL                                         $15     
         14      > RETURN                                                   $15
   11    15*     > RETURN                                                   null

End of function convertnew

Function convertold:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 21
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 21
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/lKdPn
function name:  convertOld
number of ops:  24
compiled vars:  !0 = $input, !1 = $range_input, !2 = $range_output, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        INIT_FCALL                                               'range'
          2        SEND_VAL                                                 1
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 0.00787402
          5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !1, $5
   16     7        INIT_FCALL                                               'range'
          8        SEND_VAL                                                 0
          9        SEND_VAL                                                 127
         10        DO_ICALL                                         $7      
         11        ASSIGN                                                   !2, $7
   18    12      > FE_RESET_R                                       $9      !1, ->21
         13    > > FE_FETCH_R                                       ~10     $9, !3, ->21
         14    >   ASSIGN                                                   !4, ~10
   19    15        IS_SMALLER_OR_EQUAL                                      !3, !0
         16      > JMPZ                                                     ~12, ->20
   20    17    >   FETCH_DIM_R                                      ~13     !2, !4
         18        FE_FREE                                                  $9
         19      > RETURN                                                   ~13
   18    20    > > JMP                                                      ->13
         21    >   FE_FREE                                                  $9
   24    22      > RETURN                                                   127
   25    23*     > RETURN                                                   null

End of function convertold

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.13 ms | 956 KiB | 26 Q