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

  • Home
  • SEARCH
  • 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 8889317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:13:55+00:00 2026-06-14T22:13:55+00:00

I was optimizing an algorithm. I ran into a strange oddity. The following: //The

  • 0

I was optimizing an algorithm. I ran into a strange oddity.

The following:

//The following is completely unused
vector<int>** rotated_squares;
rotated_squares = new vector<int>*[31];
for (int i=0;i<31;++i) {
    rotated_squares[i] = new vector<int>[31];
}

{
    //Lots of computation, using other vectors, but not rotated_squares
}

. . . is at least ten times slower than:

{
    //The exact same computation as above.
}

I have no idea what could be causing this. The only thing I can think of is that it is an artifact of the underlying implementation somehow. To that end, using Visual Studio 2010 for C++ compiler.

EDIT: Clarification, the computation below is the part that becomes slower. The memory allocations at the top are almost negligible when profiling.

So the issue is that I add the lines at the top, and the code runs about ten times slower. By debugging, the extra memory allocation takes a fraction of a second, but the computation code, which normally takes about eight seconds, starts to take several minutes.

EDIT: By popular demand, the source of the algorithm can be found here: http://pastebin.com/Yf78gTNC. The point is that the #if 1 can be set or unset and the code compiles fine–but with it, it runs much slower in the computation section.

EDIT: I have reduced the code to the following: http://pastebin.com/mpnPsQE1. In my code, this causes the problem. However, making a simple test case (i.e. a main function with just this code) does not show the problem.

  • 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-14T22:13:56+00:00Added an answer on June 14, 2026 at 10:13 pm

    With C+++03 and a std::vector< T const > you’ve passed into Undefined Behavior land. I am not sure of the situation with C++11, even after using like 10 minutes trawling the standard. But possibly the same, and in that case no special explanation is needed.

    However, it might be that the code that you haven’t shown, and that’s allegedly slowing down, is referencing rotated_squares.

    It might also be that the added code causes a cache miss.

    It’s rather difficult to reproduce without the code, but it just might help to put the slowed-down code in its own function.

    Engaging ESP circuit overdrive… Concentrating… Nope, that didn’t work either.

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

Sidebar

Related Questions

I am optimizing an algorithm in ARM assembly and need to figure out in
The Situation: I'm optimizing a pure-java implementation of the LZF compression algorithm, which involves
While optimizing performance of an app of mine, I ran across a huge performance
I recently posted a question about optimizing the algorithm to compute the Levenshtein Distance,
The Hitchhiker's guide to Algorithms discusses the following pointers: 1.6 Counting or Optimizing Good
I implemented a path simplification algorithm after reading the article here: http://losingfight.com/blog/2011/05/30/how-to-implement-a-vector-brush/ It's worked
Optimizing a game we're developing, we're running into the phase where every CPU cycle
When optimizing UI in our project I noticed really strange boost up in ListView
Been optimizing an algorithm and came down to the last part. I have an
I'm optimizing an sha-256 > hmac > pbkdf2 crypto algorithm in javascript for chrome

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.