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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:15:01+00:00 2026-05-28T05:15:01+00:00

class MyClass { public: MyClass() { m_dbLoopStart = 0.0; m_dbLoopStop = 100.0; m_dbLoopStep =

  • 0
class MyClass
{
    public:
        MyClass()
        {
            m_dbLoopStart   = 0.0;
            m_dbLoopStop    = 100.0;
            m_dbLoopStep    = 0.001;
        }

        // Which of the following methods complete in a shorter time?

        void Foo1() const   // This one?
        {
            for (double x=m_dbLoopStart; x<=m_dbLoopStop; x+=m_dbLoopStep)
            {
                f(x);
            }
        }

        void Foo2() const   // Or, this one?
        {
            for (double x=m_dbLoopStart; x<=m_dbLoopStop; x+=m_dbLoopStep)
            {
                2.0 * x + 1.0;
            }
        }

    private:
        double m_dbLoopStart, m_dbLoopStop, m_dbLoopStep;

        inline static double f(double x)
        {
            return 2.0 * x + 1.0;
        }
};

Between Foo1() and Foo2(), which one would complete faster?

  • 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-28T05:15:02+00:00Added an answer on May 28, 2026 at 5:15 am

    Inline functions may be faster because they avoid the cost of a function call and return overhead. Remember that compilers may choose not to inline functions.

    In most translators, function parameters must be passed and space allocated for the parameters and any function local storage. On the return side, the function local variables must be removed and usually a value returned.

    For simple functions, such as getters and setters, the overhead of the function call and return are greater than the code in the function. Thus inlining will speed up these functions.

    Inline functions also remove the branch instruction to call the function. This reduces the chance of the processor clearing out the instruction cache / pipeline. Although modern processors have implemented algorithms to reduce the negative impact of branch instructions.

    In my programming practices, I inline small (3 line or smaller) methods. If I’m going to inline for performance reasons, I’ll profile before inlining.

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

Sidebar

Related Questions

I have the following class: package x.y.z; public class MyClass{ public void someMethod(SomeObject object){
class MyClass { public: void method2() { static int i; ... } }; Will
public class MyClass { public int Age; public int ID; } public void MyMethod()
Consider the following code: public class MyClass { public static string MyStaticMethod() { //string
I'm curious about the following code: class MyClass { public: MyClass() : _myArray(new int[1024])
I have the following object: public class MyClass { public int Id { get;
Here is my class definition: class MyClass { public: void test(int val = 0);
I've got a Class with an undetermined number of methods inside Public Class MyClass
Say I have a class, something like the following; class MyClass { public: MyClass();
Is there a memory leak here? class myclass : public boost::enable_shared_from_this<myclass>{ //... void broadcast(const

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.