1

I've run the following PHP function on two different machines and consistently seen little difference in runtime - Ex. 40 sec vs 40.5 sec. Why is this?

The Two Different Builds:

  • 2.3Ghz 8-Core Intel Core I9, 16GB RAM
  • 3.8Ghz 12-Core Ryzen 9 3900x, 32GB RAM

I know that PHP runs scripts on a single core, but I'm unsure as to why the difference in clock speeds between the two processors accounted for no difference in runtime.

The Function:

This function takes a parent product, looks through its components for either a part or assembly - if a part - recursion, if not add to global variable. I know it's bad practice to use global variables, but in my application this makes sense for me.

<?php 
$masterPickList = [];

function listBuilder($itemNo, $multiplier){
    global $masterPickList;
    include "bin/inventoryConn.php";
    $assemblies = [];
    $AssemblySelect = "SELECT products.PRD_COMP_ITEM_NO,products.PRD_STR_QTY_PER_PAR, itemInfo.ITEM_DESC1,itemInfo.ITEM_DESC2,itemInfo.ITEM_P_AND_IC_CD,itemInfo.ITEM_USER_DEF_CD,itemInfo.ITEM_NO,itemInfo.ITEM_PUR_UOM 
    FROM products INNER JOIN itemInfo ON products.PRD_COMP_ITEM_NO = itemInfo.ITEM_NO WHERE products.PRD_STR_PAR_ITEM_NO = '{$itemNo}' ORDER BY PRD_COMP_ITEM_NO ASC;";
    $AssemblyResult = mysqli_query($conn, $AssemblySelect) or die("Bad Query: $AssemblySelect");
    
    while($row = mysqli_fetch_assoc($AssemblyResult))

    {
            if ($row['ITEM_P_AND_IC_CD'] !== '11' && $row['ITEM_P_AND_IC_CD'] !== '11A' && $row['ITEM_P_AND_IC_CD'] !== '90')
            {
                if (strpos($row['ITEM_NO'],'50-') !== false)
                {
                    $masterPickList[$itemNo]['SCD'][$row['ITEM_NO']]['ITEM_NO'] = $row['ITEM_NO'];
                    $masterPickList[$itemNo]['SCD'][$row['ITEM_NO']]['ITEM_DESC1'] = $row['ITEM_DESC1'];
                    $masterPickList[$itemNo]['SCD'][$row['ITEM_NO']]['ITEM_DESC2'] = $row['ITEM_DESC2']; 
                    $masterPickList[$itemNo]['SCD'][$row['ITEM_NO']]['QTY'] = intval($multiplier) * intval($row['PRD_STR_QTY_PER_PAR']);
                        if ($row['ITEM_USER_DEF_CD'] !== 'P')
                        {
                            $masterPickList[$itemNo]['SCD'][$row['ITEM_NO']]['PICK'] = '*Do Not Pick*'; 
                        } elseif ($row['ITEM_USER_DEF_CD'] == 'P')
                        {
                            $masterPickList[$itemNo]['SCD'][$row['ITEM_NO']]['PICK'] = '';
                        }
                    $masterPickList[$itemNo]['SCD'][$row['ITEM_NO']]['UM'] = $row['ITEM_PUR_UOM']; 
                }
                else
                {
                    $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['ITEM_NO'] = $row['ITEM_NO'];
                    $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['ITEM_DESC1'] = $row['ITEM_DESC1'];
                    $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['ITEM_DESC2'] = $row['ITEM_DESC2']; 
                    $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['QTY'] = intval($multiplier) * intval($row['PRD_STR_QTY_PER_PAR']);
                        if ($row['ITEM_USER_DEF_CD'] !== 'P')
                        {
                            $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['PICK'] = '*Do Not Pick*'; 
                        } elseif ($row['ITEM_USER_DEF_CD'] == 'P')

                        {
                            $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['PICK'] = '';

                        }

                    $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['UM'] = $row['ITEM_PUR_UOM']; 
                }
            

            
            } 
            else if ($row['ITEM_P_AND_IC_CD'] == '11' || $row['ITEM_P_AND_IC_CD'] == '11A' || $row['ITEM_P_AND_IC_CD'] == '90')
            {   
                $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['ITEM_NO'] = $row['ITEM_NO'];
                $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['ITEM_DESC1'] = $row['ITEM_DESC1'];
                $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['ITEM_DESC2'] = $row['ITEM_DESC2']; 
                $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['QTY'] = intval($multiplier) * intval($row['PRD_STR_QTY_PER_PAR']);
                if ($row['ITEM_USER_DEF_CD'] !== 'P')
                {
                    $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['PICK'] = '*Do Not Pick*'; 
                } elseif ($row['ITEM_USER_DEF_CD'] == 'P')

                {
                    $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['PICK'] = '';

                }

                $masterPickList[$itemNo]['COMP'][$row['ITEM_NO']]['UM'] = $row['ITEM_PUR_UOM']; 

                $assemblies[] = $row['ITEM_NO'];
          
            }
    }   
    
    foreach($assemblies as $item) {
        listBuilder($item, $multiplier);
    }
}
3
  • 2
    Clock speed is just one of the nany features that determine overall speed of a cpu Commented Aug 31, 2021 at 20:36
  • 3
    and there is more than just "CPU speed" in how long a program takes to complete. You might be bottlenecking on IO at some place, or you're using enough memory to be pushed into swap. [and then IO bottleneck] Commented Aug 31, 2021 at 20:38
  • 3
    Also, pretty much any time you think "I can't do this without a global" is actually a case for a class/object. Though at a glance yours is just a recursive function and could probably be solved via a second pass at the logic and/or use of a reference. Commented Aug 31, 2021 at 20:39

1 Answer 1

2

CPU speeds have not changed much since the year 2000. Before that, it was a useful factor in performance.

MySQL spends some of its time transferring data between processes with itself and do/from the clients. The performance of that, too, is not something to see much difference between two current servers or between an old server and a new one.

Almost everything is done serially, so multiple cores, drives, etc don't help when measuring a single task.

If everything is cached in RAM, the size of the RAM does not matter.

The only significant hardware improvement in the past decade is switching from HDD to SSD. Everything is noise.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.