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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:56:16+00:00 2026-05-25T01:56:16+00:00

i am trying to find out a way in which i can write out

  • 0

i am trying to find out a way in which i can write out run-time of selected number of functions when my tool runs. let say out of large list of functions which my tool have i need to write out the what is the time taken by individual calls y(), z() , a1() ….

X(){

 y();
 ..
 ..
 z();
 ..
 ..
 a1();
 ..
 ..
 b1();
 ..
 ..
}

I don’t want to use gprof because it need to be separately run , and there is no way customer can run gprof at there end. In many cases i don’t have access to the test which is producing long runtime. A way to log run time of high level function will be helpful. i dont’t want to wrap around each and every function call around time() system call and then print it. Can macro help in this.? any ideas?

  • 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-25T01:56:17+00:00Added an answer on May 25, 2026 at 1:56 am

    You said you don’t want to wrap each call, but let me just show you how I handle timer calls so they can be removed at compile time, and maybe that can be wrapped up in another macro later:

    #ifndef NOTIME
    #  include <ctime>
    #  define CLOCK_TICK(acc, ctr)  ctr = std::clock()
    #  define CLOCK_TOCK(acc, ctr)  acc += (std::clock() - ctr)
    #  define CLOCK_RESET(acc) acc = 0
    #  define CLOCK_REPORT(acc) 1000. * double(acc) / double(CLOCKS_PER_SEC)
    
    static clock_t t1a, t1c, t2a, t2c; // as many pairs as you need
    
    #else
    #  define CLOCK_TICK(acc, ctr)
    #  define CLOCK_TOCK(acc, ctr)
    #  define CLOCK_RESET(acc)
    #  define CLOCK_REPORT(acc) 0
    #endif
    

    Now you can use it like this:

    CLOCK_RESET(t1a);
    for (int i = 0; i != 250000; ++i)
    {
      CLOCK_TICK(t1a, t1c);
      some_expensive_function();
      CLOCK_TOCK(t1a, t1c);
    }
    std::cout << "Time spent in some_expensive_function(): " << CLOCK_REPORT(t1a) << "ms.\n";
    

    With variadic macros you might even be able to wrap up the function call:

    #define timed_call(ACC, CTR, func, ...) do { CLOCK_TICK(ACC, CTR); \
                                                 func(__VA_ARGS__);    \
                                                 CLOCK_TOCK(ACC,CTR);  \
                                               } while (false)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out a way to find out which files were affected
I'm trying to find out a way to know the index of a anchor
I am trying to find out if there is a more optimal way for
Hi I'm trying to find out if there is a way to set the
I am trying to find out what would be the best way to bind
I'm trying to find out how i can ask a browser if he supports
I'm new to Windows networking, and I am trying to find out which PORT
Given a function, I'm trying to find out the names of the nested functions
I'm trying to figure out a nice way to limit the rate at which
Is there a way in llvm that using static analysis, i can find out

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.