3v4l.org

run code in 300+ PHP versions simultaneously
<?php function convertOld($input) { $oldMin = 0; $oldMax = 1; $newMin = 127; $newMax = 0; return ceil(((($input- $oldMin) * ($newMax - $newMin)) / ($oldMax - $oldMin)) + $newMin); } function convertNew($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; } $start = microtime(1); foreach (range(0,1,1/1000) as $input) { convertOld($input); } echo "Old time: ".(microtime(1) - $start)."\n"; $start = microtime(1); foreach (rang(0,1,1/1000) as $input) { convertNew($input); } echo "New time: ".(microtime(1) - $start)."\n"; $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 = 33, Position 2 = 38
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 38
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 38
2 jumps found. (Code = 77) Position 1 = 53, Position 2 = 65
Branch analysis from position: 53
2 jumps found. (Code = 78) Position 1 = 54, Position 2 = 65
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 64
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 64
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 76
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 76
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 65
Branch analysis from position: 38
Branch analysis from position: 15
filename:       /in/BPOQj
function name:  (null)
number of ops:  78
compiled vars:  !0 = $start, !1 = $input, !2 = $warnings
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'microtime'
          1        SEND_VAL                                                 1
          2        DO_ICALL                                         $3      
          3        ASSIGN                                                   !0, $3
   28     4        INIT_FCALL                                               'range'
          5        SEND_VAL                                                 0
          6        SEND_VAL                                                 1
          7        SEND_VAL                                                 0.001
          8        DO_ICALL                                         $5      
          9      > FE_RESET_R                                       $6      $5, ->15
         10    > > FE_FETCH_R                                               $6, !1, ->15
         11    >   INIT_FCALL                                               'convertold'
         12        SEND_VAR                                                 !1
         13        DO_FCALL                                      0          
         14      > JMP                                                      ->10
         15    >   FE_FREE                                                  $6
   29    16        INIT_FCALL                                               'microtime'
         17        SEND_VAL                                                 1
         18        DO_ICALL                                         $8      
         19        SUB                                              ~9      $8, !0
         20        CONCAT                                           ~10     'Old+time%3A+', ~9
         21        CONCAT                                           ~11     ~10, '%0A'
         22        ECHO                                                     ~11
   31    23        INIT_FCALL                                               'microtime'
         24        SEND_VAL                                                 1
         25        DO_ICALL                                         $12     
         26        ASSIGN                                                   !0, $12
   32    27        INIT_FCALL_BY_NAME                                       'rang'
         28        SEND_VAL_EX                                              0
         29        SEND_VAL_EX                                              1
         30        SEND_VAL_EX                                              0.001
         31        DO_FCALL                                      0  $14     
         32      > FE_RESET_R                                       $15     $14, ->38
         33    > > FE_FETCH_R                                               $15, !1, ->38
         34    >   INIT_FCALL                                               'convertnew'
         35        SEND_VAR                                                 !1
         36        DO_FCALL                                      0          
         37      > JMP                                                      ->33
         38    >   FE_FREE                                                  $15
   33    39        INIT_FCALL                                               'microtime'
         40        SEND_VAL                                                 1
         41        DO_ICALL                                         $17     
         42        SUB                                              ~18     $17, !0
         43        CONCAT                                           ~19     'New+time%3A+', ~18
         44        CONCAT                                           ~20     ~19, '%0A'
         45        ECHO                                                     ~20
   35    46        ASSIGN                                                   !2, <array>
   36    47        INIT_FCALL                                               'range'
         48        SEND_VAL                                                 0
         49        SEND_VAL                                                 1
         50        SEND_VAL                                                 0.0001
         51        DO_ICALL                                         $22     
         52      > FE_RESET_R                                       $23     $22, ->65
         53    > > FE_FETCH_R                                               $23, !1, ->65
   37    54    >   INIT_FCALL                                               'convertold'
         55        SEND_VAR                                                 !1
         56        DO_FCALL                                      0  $24     
         57        INIT_FCALL                                               'convertnew'
         58        SEND_VAR                                                 !1
         59        DO_FCALL                                      0  $25     
         60        IS_NOT_EQUAL                                             $24, $25
         61      > JMPZ                                                     ~26, ->64
         62    >   ASSIGN_DIM                                               !2
         63        OP_DATA                                                  !1
   36    64    > > JMP                                                      ->53
         65    >   FE_FREE                                                  $23
   39    66        COUNT                                            ~28     !2
         67      > JMPZ                                                     ~28, ->76
   40    68    >   INIT_FCALL                                               'implode'
         69        SEND_VAL                                                 '%2C+'
         70        SEND_VAR                                                 !2
         71        DO_ICALL                                         $29     
         72        CONCAT                                           ~30     'Warning%2C+value+mismatches+at+', $29
         73        CONCAT                                           ~31     ~30, '%0A'
         74        ECHO                                                     ~31
         75      > JMP                                                      ->77
   42    76    >   ECHO                                                     'All+values+passed%21%0A'
   43    77    > > RETURN                                                   1

Function convertold:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BPOQj
function name:  convertOld
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 convertold

Function convertnew:
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/BPOQj
function name:  convertNew
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 convertnew

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.51 ms | 1411 KiB | 25 Q