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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:28:27+00:00 2026-05-30T18:28:27+00:00

After modifying my C code, (written originally for Windows and compiled under VS 2008),

  • 0

After modifying my C code, (written originally for Windows and compiled under VS 2008), I ran it on Linux. To my surprise it is now at least 10 times slower than windows version.

Using Profiler tools I figured out that the following function is consuming most of the time spent in the application:

/* advance by n bits */

void Flush_Buffer(N)
int N;
{
 int Incnt;


 ld->Bfr <<= N;

Incnt = ld->Incnt -= N;

if (Incnt <= 24)
{
if (System_Stream_Flag && (ld->Rdptr >= ld->Rdmax-4))
{
do
{
if (ld->Rdptr >= ld->Rdmax)
      Next_Packet();
    ld->Bfr |= Get_Byte() << (24 - Incnt);
    Incnt += 8;
  }
  while (Incnt <= 24);
}
else if (ld->Rdptr < ld->Rdbfr+2044)
{
  do
  {
    ld->Bfr |= *ld->Rdptr++ << (24 - Incnt);
    Incnt += 8;
  }
  while (Incnt <= 24);
}
else
{
  do
  {
    if (ld->Rdptr >= ld->Rdbfr+2048)
      Fill_Buffer();
    ld->Bfr |= *ld->Rdptr++ << (24 - Incnt);
    Incnt += 8;
  }
  while (Incnt <= 24);
}
ld->Incnt = Incnt;
}

}

This function was taking negligible time on windows. on Linux it is taking taking close to 14 sec. What wrong I have committed here?

There are no system calls here so this code section should be independent of OS specific calls and thus should run in identical time.

(My Guess: This function is being called multiple times, so may be the profiler is accumulating the time of all the calls too. In such a case I think one of the issues might be that the function is not getting its input parameter quickly as compared to windows case. )

What wrong I have committed here? Any guess?

Rgrds,

H

  • 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-30T18:28:28+00:00Added an answer on May 30, 2026 at 6:28 pm

    You can try to annotate all code paths in your code with counters. At the end of the program, each counter will contain information about how many times the code path has been executed. Comparing these numbers line-by-line between the Windows version and the Linux version may reveal that the program is following different code paths. Depending on the nature of the code paths, the differences may be able to explain why the Linux version is slower than the Windows version.

    int count[100];
    
    // Call this function at the end of program 
    void PrintCounts() {
        int i;
        for(i=0; i<100; i++) printf("%d\n", count[i]);
    }
    
    void Flush_Buffer(int N) {
      int Incnt;
    
      ld->Bfr <<= N;
    
      Incnt = ld->Incnt -= N;
    
      if (Incnt <= 24) {
        count[0]++;
        if (System_Stream_Flag && (ld->Rdptr >= ld->Rdmax-4)) {
          count[1]++;
          do {
             count[2]++;
             ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to rebuild my kernel after modifying some source files and noticed
I made the mistake of modifying my original source after importing it into subversion.
After being told by at least 10 people on SO that version control was
In this code from an array i am selecting a dictionary,modifying it and saving
I am currently modifying code created in the MS VS IDE, and one change
When I'm modifying code I like to comment out the old code, modify it,
i found an article about self modifying code and tried to do some examples,
After reading the Head First Design Patterns book and using a number of other
After the suggestion to use a library for my ajax needs I am going
After reading this question , I was reminded of when I was taught Java

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.