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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:16:05+00:00 2026-05-11T09:16:05+00:00

I need to profile a program to see whether any changes need to be

  • 0

I need to profile a program to see whether any changes need to be made regarding performance. I suspect there is a need, but measuring first is the way to go. This is not that program, but it illustrates the problem I’m having:

#include <stdio.h> int main (int argc, char** argv) {   FILE* fp = fopen ('trivial.c', 'r');   if (fp)   {     char line[80];     while (fgets (line, 80, fp))       printf (line);      fclose (fp);   }   return 0; } 

Here’s what I did with it:

% gcc trivial.c -pg -o trivial % ./trivial ... % gprof trivial gmon.out 

Granted, this is a trivial program, but I would have thought it would make some kind of blip on the profiling radar. It didn’t:

                                  called/total       parents  index  %time    self descendents  called+self    name       index                                   called/total       children                  0.00        0.00       1/1           __start [1704] [105]    0.0    0.00        0.00       1         _main [105]  -----------------------------------------------    %   cumulative   self              self     total             time   seconds   seconds    calls  ms/call  ms/call  name       0.0       0.00     0.00        1     0.00     0.00  _main [105]  Index by function name   [105] _main               

Can anyone guide me here? I would like the output to reflect that it called fgets and printf at least 14 times, and it did hit the disk after all – there should be some measured time, surely.

When I run the same command on the real program, I get more functions listed, but even then it is not a complete list – just a sample.

Perhaps gprof is not the right tool to use. What is?

This is on OS X Leopard.

Edit: I ran the real program and got this:

% time real_program real      4m24.107s user      2m34.630s sys       0m38.716s 
  • 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. 2026-05-11T09:16:06+00:00Added an answer on May 11, 2026 at 9:16 am

    There are certain commonly-accepted beliefs in this business, that I would suggest you examine closely.

    One is that the best (if not only) way to find performance problems is to measure the time each subroutine takes and count how many times it is called.

    That is top-down. It stems from a belief that the forest is more important than the trees. It is based on myths about ‘speed of code’ and ‘bottlenecks’. It is not very scientific.

    A performance problem is more like a bug than a quantitative thing. What it is doing wrong is it is wasting time, and it needs to be fixed. It is based on a simple observation:

    Slowness consists of time being spent for poor reasons.

    To find it, sample the program state at random slivers of clock time, and investigate their reasons.

    If something is causing slowness, then that fact alone exposes it to your samples. So if you take enough samples, you will see it. You will know approximately how much time it is costing you, by the fraction of samples that show it.

    A good way to tell if a sliver of time is being spent for a good reason is to look carefully at the call stack. Every function invocation on the stack has an implicit reason, and if any of those reasons are poor, then the reason for the entire sample is poor.

    Some profilers tell you, at the statement level, what each statement is costing you.

    Personally, I just randomly halt the program several times. Any invocations showing up on multiple samples are likely candidates for suspicion. It never fails.

    You may say ‘It’s not accurate.’ It’s extremely accurate. It precisely pinpoints the instructions causing the problem. It doesn’t give you 3 decimal places of timing accuracy. I.e. it is lousy for measurement, but superb for diagnosis.

    You may say ‘What about recursion?’. Well, what about it?

    You may say ‘I think that could only work on toy programs.’ That would be just wishing. In fact large programs tend to have more performance problems, because they have deeper stacks, thus more opportunity for invocations with poor reasons, and sampling finds them just fine, thanks.

    Sorry to be a curmudgeon. I just hate to see myths in what should be a scientifically-based field.

    MORE

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

Sidebar

Ask A Question

Stats

  • Questions 114k
  • Answers 114k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The following script will create a stationary hovering image out… May 11, 2026 at 10:19 pm
  • Editorial Team
    Editorial Team added an answer I'm not sure I'm clear on your desired use here,… May 11, 2026 at 10:19 pm
  • Editorial Team
    Editorial Team added an answer Depends on the capabilities of your shell and the size… May 11, 2026 at 10:19 pm

Related Questions

Is there a limit to the rows that IEnumerable.Count() (or IQueryable.Count()) using LINQ to
I have to analyze the memory accesses of several programs. What I am looking
In an application I need to execute other programs with another user's credentials. Currently
I'm working in a windows environment (my laptop!) and I need a couple of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.