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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:32:44+00:00 2026-05-29T06:32:44+00:00

I was thinking about doing a take_timing function that would take the timing of

  • 0

I was thinking about doing a take_timing function that would take the timing of any function passed to it. By any function it means that the arguments this callback takes is unknown by the caller. It would take too the arguments for the callback. But as it doesn’t know how to call it, it would take another callback function, the caller of the callback, written by the function user. The stub would be something like this:

void take_timing(
    void (*callback)(),
    void (*caller(void (*callback)(),void* args_struct),
    void* args_struct
)
{
    // Start timer

    caller(callback,args_struct);

    // Stop timer, read timings, record...
}

void some_caller(void (*callback)(),void* args_struct)
{
    // Cast "callback" to function signature
    // Cast args_struct to some struct with args
    // Call the callback with correct args signature
}

So comes my questions:

  1. Is it possible?
  2. Can it use variable arguments list to make it simples? How? I am helpless on this…
  3. Is there a better way of doing it? Or is it just better to do a take_timing for every specific case?
  4. Is there a OOP Design Pattern for this for use with C++?

I myself gave up on this, but put it here out of curiosity, maybe some very useful insights.

  • 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-29T06:32:45+00:00Added an answer on May 29, 2026 at 6:32 am

    Just take a functor as a template argument. Something like:

    template<typename F>
    nanoseconds take_timing(F f) {
    
        auto start = high_resolution_clock::now();
        f();
        auto end = high_resolution_clock::now();
        return end - start;
    }
    
    long long factorial(int i);
    
    take_timing( [](){factorial(20);} ); // wrap call to function taking arguments in zero-argument lambda
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just thinking about the best way to build an Order form that would (from
I'm looking to make my own custom < function that can take any number
Thinking about a Windows-hosted build process that will periodically drop files to disk to
Thinking about avoiding code replication, I got a question that catches me every time
While thinking about this question and conversing with the participants, the idea came up
Been thinking about this for hours now. Im building a simple slideshow application, where
I'm sure there's a really easy way of doing this. I'm trying to take
I have two rails apps that I am thinking about merging into one because
I've been thinking about doing my own language (practicality: it's a thought experiment). One
This is just something I've been thinking about and was wondering if it exists,

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.