3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Crate json string contain 50000 objecy $locations = ""; for ($i=0; $i<50000; $i++){ $locations .= "{\"location\":\"$i\",\"distance\":\"25.75206\"},"; } $json = "[".substr($locations, 0, -1)."]"; $location = '100'; // Using json_decode and loop $time = microtime(true); $locations = json_decode($json, true); foreach ($locations as $key => $value) { if ($value['location'] == $location) { @$distance = $value['distance']; } } echo "json_decode and loop:\n".(microtime(true) - $time)."\n"; // Using regex $time2 = microtime(true); if (preg_match("/\{\s*\"location\"\s*:\s*\"{$location}\".*?}/", $json, $match)){ $locations = json_decode("[{$match[0]}]", true)[0]; $distance = $locations['distance']; } echo "regex: \n".(microtime(true) - $time2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 3
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 36
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 36
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 35
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 35
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 69
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 69
Branch analysis from position: 36
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 3
Branch analysis from position: 10
Branch analysis from position: 3
filename:       /in/VCa0c
function name:  (null)
number of ops:  76
compiled vars:  !0 = $locations, !1 = $i, !2 = $json, !3 = $location, !4 = $time, !5 = $value, !6 = $key, !7 = $distance, !8 = $time2, !9 = $match
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, ''
    4     1        ASSIGN                                                       !1, 0
          2      > JMP                                                          ->8
    5     3    >   ROPE_INIT                                         3  ~13     '%7B%22location%22%3A%22'
          4        ROPE_ADD                                          1  ~13     ~13, !1
          5        ROPE_END                                          2  ~12     ~13, '%22%2C%22distance%22%3A%2225.75206%22%7D%2C'
          6        ASSIGN_OP                                         8          !0, ~12
    4     7        PRE_INC                                                      !1
          8    >   IS_SMALLER                                                   !1, 50000
          9      > JMPNZ                                                        ~17, ->3
    7    10    >   FRAMELESS_ICALL_3                substr              ~18     !0, 0
         11        OP_DATA                                                      -1
         12        CONCAT                                               ~19     '%5B', ~18
         13        CONCAT                                               ~20     ~19, '%5D'
         14        ASSIGN                                                       !2, ~20
    8    15        ASSIGN                                                       !3, '100'
   11    16        INIT_FCALL                                                   'microtime'
         17        SEND_VAL                                                     <true>
         18        DO_ICALL                                             $23     
         19        ASSIGN                                                       !4, $23
   12    20        INIT_FCALL                                                   'json_decode'
         21        SEND_VAR                                                     !2
         22        SEND_VAL                                                     <true>
         23        DO_ICALL                                             $25     
         24        ASSIGN                                                       !0, $25
   13    25      > FE_RESET_R                                           $27     !0, ->36
         26    > > FE_FETCH_R                                           ~28     $27, !5, ->36
         27    >   ASSIGN                                                       !6, ~28
   14    28        FETCH_DIM_R                                          ~30     !5, 'location'
         29        IS_EQUAL                                                     !3, ~30
         30      > JMPZ                                                         ~31, ->35
   15    31    >   BEGIN_SILENCE                                        ~32     
         32        FETCH_DIM_R                                          ~33     !5, 'distance'
         33        ASSIGN                                                       !7, ~33
         34        END_SILENCE                                                  ~32
   13    35    > > JMP                                                          ->26
         36    >   FE_FREE                                                      $27
   18    37        INIT_FCALL                                                   'microtime'
         38        SEND_VAL                                                     <true>
         39        DO_ICALL                                             $35     
         40        SUB                                                  ~36     $35, !4
         41        CONCAT                                               ~37     'json_decode+and+loop%3A%0A', ~36
         42        CONCAT                                               ~38     ~37, '%0A'
         43        ECHO                                                         ~38
   21    44        INIT_FCALL                                                   'microtime'
         45        SEND_VAL                                                     <true>
         46        DO_ICALL                                             $39     
         47        ASSIGN                                                       !8, $39
   22    48        INIT_FCALL                                                   'preg_match'
         49        ROPE_INIT                                         3  ~42     '%2F%5C%7B%5Cs%2A%22location%22%5Cs%2A%3A%5Cs%2A%22'
         50        ROPE_ADD                                          1  ~42     ~42, !3
         51        ROPE_END                                          2  ~41     ~42, '%22.%2A%3F%7D%2F'
         52        SEND_VAL                                                     ~41
         53        SEND_VAR                                                     !2
         54        SEND_REF                                                     !9
         55        DO_ICALL                                             $44     
         56      > JMPZ                                                         $44, ->69
   23    57    >   INIT_FCALL                                                   'json_decode'
         58        ROPE_INIT                                         3  ~47     '%5B'
         59        FETCH_DIM_R                                          ~45     !9, 0
         60        ROPE_ADD                                          1  ~47     ~47, ~45
         61        ROPE_END                                          2  ~46     ~47, '%5D'
         62        SEND_VAL                                                     ~46
         63        SEND_VAL                                                     <true>
         64        DO_ICALL                                             $49     
         65        FETCH_DIM_R                                          ~50     $49, 0
         66        ASSIGN                                                       !0, ~50
   24    67        FETCH_DIM_R                                          ~52     !0, 'distance'
         68        ASSIGN                                                       !7, ~52
   26    69    >   INIT_FCALL                                                   'microtime'
         70        SEND_VAL                                                     <true>
         71        DO_ICALL                                             $54     
         72        SUB                                                  ~55     $54, !8
         73        CONCAT                                               ~56     'regex%3A+%0A', ~55
         74        ECHO                                                         ~56
         75      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
151.13 ms | 1202 KiB | 16 Q