We help IT Professionals succeed at work.

Please Otimize the VC++ code

351 Views
Last Modified: 2013-11-20
Hi Experts,
Can Any one can Optimize this code
typedef struct
{
  CString sSelectedConName;
 CString sSelectedPinNum;
}sFastModeData;
sFastModeData sConnectedLines[50000];
for (j = 0; j < ocon_Pins[i].nMaxPins; j++)
{
      if(m_bFastModeSelected == TRUE)
      {
      bFoundInTable = FALSE;
      for(iIndex = 0; iIndex < iIndexNoOfLinesSelected; iIndex++)
      {
      if((sConnectedLines[iIndex].sSelectedConName.Compare(sCNam[i]) == 0) &&              onnectedLines [iIndex].sSelectedPinNum.Compare(ocon_Pins[i].sPinID[j]) == 0)
      {
               bFoundInTable = TRUE;
               break;
      }
      }
      sQuery.Format("select * from TEST_P where ([name] = '%s') and       ([source-connector-name] = '%s') and (BINARY_CHECKSUM([source-pin-id]) =       BINARY_CHECKSUM('%s'))", g_sParentItem3 ,sCNam[i], ocon_Pins[i].sPinID[j]);
      if(testp.IsOpen())
         testp.Close();
      testp.Open(CRecordset::snapshot, sQuery);
                    while(!testp.IsEOF())
      {
            bFoundDestInTable = FALSE;
            for(iIndex =0; iIndex < iIndexNoOfLinesSelected; iIndex++)
            {
if((sConnectedLines[iIndex].sSelectedConName.Compare(sCNam[i]) == 0) &&                   sConnectedLines[iIndex].sSelectedPinNum.Compare(ocon_Pins[i].sPinID[j]) == 0)
            {
                  bFoundDestInTable = TRUE;
                  break;      
            }
            }
            if(bFoundDestInTable == FALSE)
            {
                  sConnectedLines[iIndexNoOfLinesSelected].sSelectedConName =                   testp.m_destination_connector_name;
                  sConnectedLines[iIndexNoOfLinesSelected++].sSelectedPinNum =                   testp.m_destination_pin_id;                  
            }
            testp.MoveNext();
      }
            
      }
      if(bFoundInTable == FALSE)
            LoadFlexGrid(g_sParentItem3, sCNam[i], "ALL", ocon_Pins[i].sPinID[j],             "PINS", 1, true);
      
}
I need faster execution of the above code
Thank you in Advance
Comment
Watch Question

AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
Which is the slow section ?

Author

Commented:
Hi,

The Billow query and Corresponding Condition Checking,
 sQuery.Format("select * from TEST_P where ([name] = '%s') and       ([source-connector-name] = '%s') and (BINARY_CHECKSUM([source-pin-id]) =       BINARY_CHECKSUM('%s'))", g_sParentItem3 ,sCNam[i], ocon_Pins[i].sPinID[j]);
      if(testp.IsOpen())
         testp.Close();
      testp.Open(CRecordset::snapshot, sQuery);
                    while(!testp.IsEOF())
      {
            bFoundDestInTable = FALSE;
            for(iIndex =0; iIndex < iIndexNoOfLinesSelected; iIndex++)
            {
if((sConnectedLines[iIndex].sSelectedConName.Compare(sCNam[i]) == 0) &&                   sConnectedLines[iIndex].sSelectedPinNum.Compare(ocon_Pins[i].sPinID[j]) == 0)
            {
                  bFoundDestInTable = TRUE;
                  break;      
            }
            }

Deepu

Author

Commented:
I am using Back end as SQL Server 2005
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
Check the fields you filter on are indexed, if not then make them indexed
AxterSenior Software Engineer
CERTIFIED EXPERT

Commented:
AndyAinscow recommendation is a good start.

I also recommend you profile your code, so you can determine exactly what section is causing the performance problem.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.