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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:03:38+00:00 2026-06-17T13:03:38+00:00

Suppose the code blow is my class. It’s simplified and not complete. Let’s focus

  • 0

Suppose the code blow is my class. It’s simplified and not complete. Let’s focus on the implementation of operator().

class Delta{
public:
    long long operator()() {
        auto now = steady_clock::now(); 
        auto delta = (now - last).count();
        last = now;
        return delta;
    }
private:
    steady_clock::time_point last;
};

operator() may be called thousands of times per second. I just wonder frequently allocate and deallocate variable now and delta may hurt the performance of operator(). So is it better to make now and delta data member of class Delta if I want to maximize the speed? But I also heard that local variable may not even exists when compiled. So somehow the overhead does not exists either.

well, actually the speed of this operator doesn’t make any difference to my Application’s speed. I just wan’t to know a compiler-neutral answer. When this situation comes. Should I make it data members or local variables?

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

    On x86-64, I’d expect this code to end up with both now and delta allocated in RAX. In assembly language, the code would look something on this order:

    assume RSI:ptr _Delta
    call steady_clock::now()
    sub rax, [rsi].last
    mov [rsi].last, rax
    ret
    

    Of course, in real assembly language, you’d see the mangled names for steady_clock::now() (for one example), but you get the general idea. Upon entry to any non-static member function, it’s going to have this in some register. The return value always goes in rax. I don’t see any particularly good reason a compiler would need (or even want) to allocate space for any other variables.

    On 32-bit x86, there’s a much higher likelihood that this would end up using some stack space, though it’s possible that it would return a 64-bit value in EDX:EAX, in which case things would end up fairly similar to what’s above, just using one more register.

    Most other processors start out with more registers than an x86, so the register pressure is lower. On a SPARC, for example, a routine will normally start with 8 local registers free and ready for use, so allocating now in a register would be a near certainty.

    Bottom line: you’re unlikely to see a significant speed difference, but if you do see a difference, I’d guess it’s more likely to favor using a local variable than a member variable.

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

Sidebar

Related Questions

Suppose this code: public class Test{ public static void main(String[] args) { Test.testInt(new int[]{2,3});
let us suppose some (legacy) code, which cannot be touched, declare struct B{ public:
Suppose code like this: class Base: def start(self): pass def stop(self) pass class A(Base):
Suppose my code is like this: <td class=apple> <div class=worm> text1 </div> </td> <td
Suppose the following code declarations: itcl::class ObjectA { private variable m_ownedObject private variable m_someVariable
Suppose the following code: class A end a = A.new As = class <<
Suppose I have code like this: template<class T, T initial_t> class Bar { //
Suppose I have code like this: container.RegisterType<IService, Implementation>(name, manager, new InjectionConstructor(...)); Then I need
I am facing a serious issue with sprintf . Suppose my code snippet is:
How to get generic interface type for an instance ? Suppose this code: interface

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.