#1
  1. A Change of Season
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,536
    Rep Power
    221

    If you had to rate it from 1-100, what would you go for? Code optimization part 1


    Hi;

    I have been testing code and it seems to be ok but there's a good chance I be wrong

    Not sure what's a good M-usage or load time.

    MEMORY USAGE 2,519,960 bytes

    Loading Time: Base Classes 0.0081
    Controller Execution Time 0.0506
    Total Execution Time 0.0590



    I upload the full report ====> here <====

    It is not perfect, some duplicate queries etc.

    I still want to make sure this there is no series issues with this way of retrieving data.

    I pass things between queries and classes quite often. Like this

    PHP Code:
    public function validate($launch_id,$redirect null)    
            {
                
    $this->launch_library->is_valid_launch($launch_id);
                if(
    $redirect==1)
                    {
                        
    $status $this->page_access_library->is_broadcast_open($launch_id);
                        
    /* 
                            is_broadcast_open returns 1,2 or 3
                                1 = Open
                                2 = Closed
                                3 = Will Open Soon
                        */
                        
    if($status==1)
                            {
                                
    $redirect_url $this->launch_library->launch_sales_page($launch_id);
                            }
                        if(
    $status==2)
                            {
                                
    $redirect_url $this->launch_library->offer_closed_page($launch_id);
                            }
                        if(
    $status==3)
                            {
                                
    $redirect_url base_url('coming-soon/'.$launch_id);
                            }
                        
    redirect($redirect_url);             ;
                    }    
                return 
    $this->data['link'] = base_url("bc-redirect/".$launch_id."");
            } 
    page_access_library

    PHP Code:
    public function is_broadcast_open($launch_id)
                  {
                     
    /*
                    1 = Open
                    2 = Closed
                    3 = Will Open Soon
                    */
                    
    $CI =& get_instance();
                    
    $CI->launch_library->is_valid_launch($launch_id);
                    
    $query $CI->db->get_where('launch_launches', array('id' => $launch_id));
                    
    $results $query->result_array()[0];

                    
    $CI->custom_functions->set_timezone($results['launch_timezone']);
                    
                    
    $difference strtotime('now') - strtotime($results['offer_close_date']." ".$results['offer_close_time']);
                    if(
    $difference 0)
                      {
                        
    $return 1;
                      }
                    else 
                      {
                        
    $return 2;
                      }
                    
    $difference strtotime('now') - strtotime($results['offer_open_date']." ".$results['offer_open_time']);  
                    if(
    $difference 0)
                      {
                        
    $return 3;
                      }
                    return 
    $return;  
                  } 
    So yes, performance-wids, if you had to rate it from 1-100, what would you go for?

    ++++++++++++++++++++++++++++++++++++++++++++++++++++

    Edits:

    1 - Note, my goal is not perfection, it's robustness.
    2 - In the case of the duplicate queries, they seem to happen since the classes are not tighet to each other. Mostly happen for validation. If valid item for example. Just to experiment, I made a loop with 500 queries. Not much change in the load time and prtofiler details!
    3 - Does it make a BIG difference to update the code and change let's say 4 queirs to 1? or not worth the headache since ech query takes 0.0001 seconds.
    4 - I underdstand Requinex is not fully for using strtotime like this.

    Tanx
    Last edited by English Breakfast Tea; May 22nd, 2018 at 08:00 PM.

IMN logo majestic logo threadwatch logo seochat tools logo