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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:11:59+00:00 2026-06-16T13:11:59+00:00

Long story short, I’m recoding a very CPU hungry app, going to restructure it

  • 0

Long story short, I’m recoding a very CPU hungry app, going to restructure it in an entirely different way, and change alot of it’s inner workings. I was looking for a good way to compare old and new results.

Say I start by changing how function foo() works:

I want to have the program run for say, 60 seconds, and measure the % of CPU that function is using within the program’s total CPU usage. If it’s at a constant 25%, I want to know how much of those 25% is my function. Then I’ll test after changing code, and have two good indicators of whether I had a good improvement.

I’ve tried Very Sleepy but I can’t get access to the functions I wanted access to; they do not show. I want to be able to see the % usage of the function I CODED MYSELF that uses the library’s functions (SDL), yet it will only show me SDL Functions.

  • 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-16T13:12:00+00:00Added an answer on June 16, 2026 at 1:12 pm

    There are a few different ways, one of which is to simply add a high precision timer call at the start and end of the function. Depending on the number of calls to your function, you can either accumulate the time, e.g:

     typedef type_of_time_source tt;
     tt total = 0;
    
     void my_func(....)
     {
         tt time = gettime();
    
         ... lots of your code ... 
    
         time = gettime() - time;
         total += time;
     }
    

    Or you can store the individual intervals, e.g.

     tt array[LARGE_NUMBER];
     int index = 0;
    
    
     ... same code as above ... 
         time = gettime() - time;
         if (index >= LARGE_NUMBER) index = 0; // [or LARGE_NUMBER-1?]
         array[index++] = time;
    

    Of course, if your calls to SDL are in the middle of your function, you need to one way or another discount that time.

    Another method would be to measure the individual timing of several functions:

     enum {
         FUNCA,
         FUNCB,
         ....
         MAX_TIMINGS
    }
    
    struct timing_val
    {
        tt start, end;
        char *name;
    }
    struct timing_val timing_values[MAX_TIMINGS];
    
    #define START(f)   do { timing_values[f].name = #f; timing_values[f].start = gettime(); } while (0);
    #define END(f)  do { timing_values[f].end = gettime(); } while(0);
    
    void report()
    {
         for(int i = 0; i < MAX_TIMING; i++)
         {
               if (timing_values[i].start == 0 && timing_vlaues[i].end
                    cout << timing_values[i].name <<< " time = " << 
                         timing_values[i].end - timing_values[i].start << endl;
         }
    }
    
    void big_function()
    {
        START(FUNCA);
        funca();
        END(FUNCA);
        START(FUNCB);
        funcb();
        END(FUNCB)
    
        ... 
    
        report();
    }
    

    I’ve certainly used all of these functions, and as long-running as the functions are reasonably large, it shouldn’t add much overhead.

    You can also measure several functions at once, e.g. if we want to have the WHOLE function, we could just add the enum “BIG_FUNC” to the enum list above, and do this:

    void big_function()
    {
        START(BIG_FUNCTION);
        START(FUNCA);
        funca();
        END(FUNCA);
        START(FUNCB);
        funcb();
        END(FUNCB)
    
        ... 
        END(BIG_FUNCTION);
        report();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long story short: I'm trying to write an app that'll dump IE's history to
Long story short, here's what i'm going to be trying to do: There is
Long story short, I am looking for the best way to quickly and efficently
Long story short I'm curious if there is any way to pull the the
I have complicated query over very big table. Long story short, when I use
Long story short, we found files promoting prescription drugs on our server that we
Long story short, I have an ASP.NET application I'm trying to debug and at
Long story short, I'm developing a theme template for a blog that enables you
Long story short, the database I'm using needs to get looked at. Until that
Long story short is I tried to quickly update a single row in SQL

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.