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 7087941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:44:10+00:00 2026-05-28T07:44:10+00:00

Which function is more efficient? int rows=20000; int col=30000; void func1() { for(i=0;i<rows;i++) {

  • 0

Which function is more efficient?

int rows=20000;
int col=30000;

void func1() {
    for(i=0;i<rows;i++) {
        for(j=0;j<col;j++)
            print(a[i][j]);
    }
}

void func2() {
    for(j=0;j<col;j++) {
        for(i=0;i<rows;i++)
            print(a[i][j]);
    }
}
  • 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-05-28T07:44:11+00:00Added an answer on May 28, 2026 at 7:44 am

    Performance will probably be better for the first function because the data being accessed is arranged sequentially (or mostly sequentially) in memory. This is faster because doing a read on one memory location will cause adjacent memory locations to be brought into the cache, so when they are read, they will be read much faster than if they weren’t in the cache.
    _
    The reason everyone should really know about things like this is because the performance difference can be absolutely dramatic. About 5 years ago, I was working on optimizing the performance of a project that had code like in the second function. I was able to increase the speed of some loops just like that by a factor of 10 when programming in C by accessing memory sequentially.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The question is simply between $(body).click(function(e){}); vs $(document).click(function(e){}); which is more efficient or advisable?
The title more or less says it all: I have a function which takes
i'm using function pointers typedef'd: typedef int(*ptr2Func)(); And a function which when given a
I am wondering which way is more efficient using jQuery data to bind data
This <cfif len(x)> Or <cfif x NEQ > Which one is more efficient and
I've been using debug() more often now, but sometimes I wonder which functions have
Hallo, how can I pass more parameters to usort? I have different functions, which
which function windows is calling to list the files in a directory ? thanks
Which function can I use to get the content of a plain text file?
I'm writing a construct in PHP where a parser determins which function to call

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.