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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:25:14+00:00 2026-05-27T09:25:14+00:00

My C program is efficiency critical. Some functions are called millions of times, so

  • 0

My C program is efficiency critical. Some functions are called millions of times, so I would like to know how much time is spent on each function, giving me sth like this:

Total time: 100s
forward(): 20s;
align(): 15s;
...
others: 1s.

Is there any debugger can perform such analysis? I am using Eclipse CDT on Ubuntu, and using gdb to debug. Some guy suggested Valgrind, but I did not find any suitable. I found there are some questions talking about c# or php or perl profiling, any suggestions for C? Thanks.

===========================================

Follow up: thanks very much for all help, gprof seems really nice. Here is a manual link: http://www.cs.utah.edu/dept/old/texinfo/as/gprof_toc.html.

A question about interpreting the summary:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  us/call  us/call  name    
 61.29      9.18     9.18                             bwa_print_sam_SQ
 21.96     12.47     3.29                             bwt_sa
  4.01     13.07     0.60                             bns_coor_pac2real
  3.87     13.65     0.58                             bwt_match_exact_alt
  2.60     14.04     0.39                             bwa_read_seq
  1.00     14.19     0.15                             bwt_match_gap
  0.80     14.45     0.12                             seq_reverse

If I am not wrong, it says the function bwa_print_sam_SQ takes 61.29% of the total time. But my program runs for 96.24 seconds, this function should run around 60 seconds. Why the column “cumulative” seconds is only 9.18? The manual says:

cumulative seconds
    This is the cumulative total number of seconds the computer spent executing this functions, plus the time spent in all the functions above this one in this table. 

And I use the parameter

"gprof -f pe_sai2sam_se_core -f bwa_print_sam_SQ -f seq_reverse ./peta > gprof", 

where function “pe_sai2sam_se_core” calls “bwa_print_sam_SQ” in a big while loop. Why the report says:

index % time    self  children    called     name
                                                 <spontaneous>
[1]     61.3    9.18    0.00                 bwa_print_sam_SQ [1]
-----------------------------------------------
                                                 <spontaneous>
[8]      0.8    0.12    0.00                 seq_reverse [8]
-----------------------------------------------

It did not say anything about pe_sai2sam_se_core… Why?

  • 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-27T09:25:14+00:00Added an answer on May 27, 2026 at 9:25 am

    You don’t need a debugger. What you need is called a profiler. Since you mention Ubuntu, you probably want to start with gprof.

    Here’s how you can use gprof:

    • Disable all compiler optimizations for your program (-O0) – optional of course
    • Add the -g and the -pg flags
    • Rebuild and run the program as usual
    • At this point your program should have produced a gmon.out file in the cwd
    • Use gprof to inspect data:

      gprof ./your_program > prof
      

    Now you can view the prof file. It begins with the flat profile which simply tells you how much time it’s spending in various functions.

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

Sidebar

Related Questions

I would like to use singleton pattern in a multithreaded program. Double-checked locking method
I invoked getpid() in a program for many times (to test the efficiency of
I want to know whether there is an effect on program efficiency by adopting
Most program languages have some kind of exception handling; some languages have return codes,
A program receives a list of Messages (base type). Each message in the list
I am trying to execute some queries using YQL. To gain some efficiency, I
What is the purpose of abstraction in coding: Programmer's efficiency or program's efficiency? Our
I have a question about improving the efficiency of my program. I have a
I need to write a program which does 2 tasks at the same time
How would you rate the efficiency of a certain design? What are your variables?

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.