Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8832593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:34:09+00:00 2026-06-14T08:34:09+00:00

This is my code: $size_all_colonies = sizeof($all_colonies) ; $size_all_coods = sizeof($all_cood) ; for (

  • 0

This is my code:

    $size_all_colonies = sizeof($all_colonies) ;
    $size_all_coods = sizeof($all_cood) ;
    for ( $i = 0 ; $i < $size_all_colonies  ; $i++ )
    {
        $id = $all_colonies[$i]['id'] ;
        $colony_name = $all_colonies[$i]['colony_name'] ;
        $colony_node = $dom->createElement('colony');
        $response->appendChild($colony_node);
        $colony_text_node = $dom->createTextNode($colony_name) ;
        $colony_node->appendChild($colony_text_node) ;

        $id_node = $dom->createElement('id_node') ;
        $colony_node->appendChild($id_node) ;
        $id_node->appendChild($dom->createTextNode($id)) ;

        $coods = "" ;
        for ( $j = 0 ; $j < $size_all_coods ; $j++ )
        {
            if ( $id == $all_cood[$j]['colony_id'] )
            {

                $coods .= $all_cood[$j]['latitude'].",".$all_cood[$j]['longitude'].";" ;
               // break ; 
            }
        }
        $coods =substr($coods,0,-1);
        $cood_node = $dom->createElement('cood_node') ;
        $colony_node->appendChild($cood_node) ;
        $cood_node->appendChild($dom->createTextNode($coods)) ;
        echo $id . '   ' ;
    }

Explanation:

all_colonies = is a multi-dimensional array – size- 7000

all_coods – another multi array – size 70000

all_cood[$j][‘colony_id’] is foreign key and corresponds to all_colonies[$i][‘id’].

This is constructing a response for an ajax request, which ideally should take a few minutes, but is taking a few hours 🙁 . And it slows down gradually, like the first 1000 loops/iterations (outer for) happen in under 30 seconds, but the next thousand takes minutes, and the next thousand forever.

Please help!

Thanks

edit: the break statement was not required! I added when I was desperate to improve the performance, but it should not be there..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:34:11+00:00Added an answer on June 14, 2026 at 8:34 am

    Something you could try is setting up the all_coods variable to be indexed by the id, rather than just being an array. This way you will save time with the inner loop.

    For example:

    $list = tons of stuff
    
    //now, loop through the stuff once to generate 
    //the assoc array that's indexed by IDs
    $listMap = array();
    foreach($list as $item) {
        $listMap[$item['id']] = $item;
    }
    
    //the main looping
    foreach(loop an array) {
        if(isset($listMap[$id])) {
            //you just saved looping through the other array.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code in a function: Response.Clear(); Response.ContentType = text/xml; charset=utf-8;
In this code, for vector size, n >=32767, it gives segmentation fault, but upto
i have this CSS code: h1 { font-size:22px; color:#341C12; font-weight:normal; font-style:italic; } .h1color h1{
i have this code: $('.access a').toggle(function() { $('link').attr('href', 'styles/accessstyles.css'); $('body').css('font-size', '16px'); }, function() {
Something must be wrong with this code right here: + (UIImage*)captureView:(UIView *)theView { UIGraphicsBeginImageContext(theView.frame.size);
Hi, i'm have this code for initialize my class. - (id)initWithSize:(int)size { self =
I wrote this tiny code: #include <stdio.h> int main() { size_t temp; temp =
This is my code, which allocates space for a matrix of size specified by
This is the code. I want to align text at bottom <p style=background:#eee;font-size:1.3em;color:#022662;height:116px> <img
this is my code: <a4j:outputPanel ajaxRendered=true> <h:form> <rich:dataTable id=iprangesList value=#{ipRangeOverviewAction_publicIpRangeList} var=iprange rendered=#{ipRangeOverviewAction_publicIpRangeList.size>0} style=width: 100%

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.