Thread: how fast is inline functions?

  1. #1
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196

    Question how fast is inline functions?

    how fast is inline functions....if the function is really small like
    return a*b;

    a split second....? or faster...i really want to know..thanks

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    An inline function is simply a function that does not involve a function call.

    Code:
    int mul_slow(int a, int b) {
        return a * b;
    }
    
    inline int mul(int a, int b) {
       return a * b;
    }
    The first function (assuming a non-optimizing compiler) will have to push arguments onto the stack and call a function, whereas the second will be 'expanded' into the 'calling' code.. but there will be no actual function call, no messing with the stack. Inline doesn't make a function fast, it just doesn't add the overhead of a function call.

    As for the speed, try it on your own compiler. You will be able to call line functions more than a million times a second, so that's probably less than a split second (for definitions of split second which have duration greater than a microsecond ).
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >how fast is inline functions
    The execution time of inline functions are unque to the function and the compiler that runs it, do some profiling to get an idea of the execution time on your compiler.

    -Prelude
    My best code is written with the delete key.

  4. #4
    booyakasha
    Join Date
    Nov 2002
    Posts
    208

    Re: how fast is inline functions?

    Originally posted by nextus
    a*b;

    a split second....? or faster...i really want to know..thanks [/B]
    Assuming a and b are some primative data type number ( as opposed to some complicated class ) then a * b will only take a very small fraction of a second to complete, and being that your function is inline no overhead of a function call and return will be added.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. conditional breakpoints and inline functions
    By Mario F. in forum C++ Programming
    Replies: 2
    Last Post: 08-10-2006, 08:30 PM
  2. Inline functions and passing by value
    By gentinex in forum C++ Programming
    Replies: 8
    Last Post: 06-07-2006, 06:53 AM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  4. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM
  5. inline friend functions.
    By sean in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2002, 12:37 PM