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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:45:02+00:00 2026-06-05T18:45:02+00:00

I have a program made up of several .h and .c files and a

  • 0

I have a program made up of several .h and .c files and a lot of functions. And there are functions which call other functions and so on.
Now, this is actually an assignment so I know how much time the program needs to reach the end.

The problem is, my program takes too much time compared to the times I am given.
Is it possible to find out which function is taking too much time or which part of the code is holding the program down?


I did not give the code here because it is too long. I know that no one can answer why “my program” is slow but I am talking in general!
Is there a tool that measures how much time each function takes or something similar?
I am using gcc and I’m on Linux.

  • 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-05T18:45:05+00:00Added an answer on June 5, 2026 at 6:45 pm

    Since you are on linux, you probably have the gprof profiler installed already. The most basic use of gprof is by compiling with the -pg option (the -g option is also needed to get informative output). e.g.

    > gcc -g -pg -o my_executable my_file.c
    

    Now, you can just run your program normally. Then you run

    > gprof my_executable > profile.txt
    

    which will output the profiling information into profile.txt. This data looks a little like

    Flat profile:
    
    Each sample counts as 0.01 seconds.
      %   cumulative   self              self     total           
     time   seconds   seconds    calls  ms/call  ms/call  name    
     33.34      0.02     0.02     7208     0.00     0.00  open
     16.67      0.03     0.01      244     0.04     0.12  offtime
     16.67      0.04     0.01        8     1.25     1.25  memccpy
     16.67      0.05     0.01        7     1.43     1.43  write
     16.67      0.06     0.01                             mcount
      0.00      0.06     0.00      236     0.00     0.00  tzset
      0.00      0.06     0.00      192     0.00     0.00  tolower
      0.00      0.06     0.00       47     0.00     0.00  strlen
      0.00      0.06     0.00       45     0.00     0.00  strchr
      0.00      0.06     0.00        1     0.00    50.00  main
      0.00      0.06     0.00        1     0.00     0.00  memcpy
      0.00      0.06     0.00        1     0.00    10.11  print
      0.00      0.06     0.00        1     0.00     0.00  profil
      0.00      0.06     0.00        1     0.00    50.00  report
    
    [...]
    

    and you can read off some data about each function (e.g. open was called 7208 times and 0.02s were spent executing it.). That example data was borrowed from this guide, which you should read as it gives much more explanation and describes to how manipulate the profiling to get things like line-by-line profiling.

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

Sidebar

Related Questions

I have made a program that scans rss feeds. This same program creates feeds
Problem: Have made a small mail program which works perfectly on my developer pc
I have run into yet another issue with my program. I have made several
So I have this Java project made up of several classes, some external JAR
I have a program which is made up of 5 pages and a main
In my processing program, I have made several circles positioned randomly. I used the
I am trying to remake a program I have made in C# in OBJ-C.In
I have made a registration program. Making use of mysql database. Can I still
I have made a script that uses a program called Diascope, its a video
i have made a small opengl program using the d programming language. what i

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.