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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:40:02+00:00 2026-06-04T00:40:02+00:00

for (int i = 0; i < 5000; i++) for (int j = 0;

  • 0
for (int i = 0; i < 5000; i++)
   for (int j = 0; j < 5000; j++)
   {
      for (int ii = 0; ii < 20; ii++)
          for (int jj = 0; jj < 20; jj++)
           {
               int num = matBigger[i+ii][j+jj];
               // Extract range from this.
               int low = num & 0xff;
               int high = num >> 8;
               if (low < matSmaller[ii][jj] && matSmaller[ii][jj] > high)
                  // match found
           }
   }

The machine is x86_64, 32kb L1 cahce, 256 Kb L2 cache.

Any pointers on how can I possibly optimize this code?

EDIT Some background to the original problem : Fastest way to Find a m x n submatrix in M X N matrix

  • 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-04T00:40:04+00:00Added an answer on June 4, 2026 at 12:40 am

    Some basic advice:

    1. Profile it, so you can learn where the hot-spots are.
    2. Think about cache locality, and the addresses resulting from your loop order.
    3. Use more const in the innermost scope, to hint more to the compiler.
    4. Try breaking it up so you don’t compute high if the low test is failing.
    5. Try maintaining the offset into matBigger and matSmaller explicitly, to the innermost stepping into a simple increment.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my code : connection.setConnectTimeout(5000); ObjectOutputStream out=new ObjectOutputStream(connection.getOutputStream()); out.writeObject(to_be_sent); out.flush(); out.close(); int resp_code=connection.getResponseCode();
I have the following code: int i = 5000; Console.WriteLine(waiting + i + miliseconds);
int max(int N, ...){ int* x = &N; x = x + 1; int
This code loops forever: #include <iostream> #include <fstream> #include <sstream> int main(int argc, char
If I run: FILE* pFile = fopen(c:\\08.bin, r); fpos_t pos; char buf[5000]; int ret
So far, I have this code sample: ... int nbytes =0; vector<unsigned char> buffer;
This is the main code of my server program in C: int main(int argc,
#include <stdio.h> #include <string.h> #define MAXLINES 5000 char *lineptr[MAXLINES]; int readlines(char *lineptr[], int nlines);
I'd like to change float like this way: 10.5000 -> 10.5 10.0000 -> 10
CREATE TABLE post( 'id' int UNSIGNED AUTO_INCREMENT, 'title' VARCHAR(100), 'content' VARCHAR(5000), 'writer' VARCHAR(100), 'updated_at'

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.