C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 1st, 2006, 06:39 PM
welkin welkin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 4 welkin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 36 sec
Reputation Power: 0
Help on inline; it doesn't work properly

Does anyone know what are some possible reasons that inline doesn't actually inline the functions? (I have already tried google up the usage for inline and I don't see how my program fails to adhere to the rules...) Right now I have a program that looks like..

...

int f1(...);

inline int f1(...) {
some work here, then return some integer.
}


void f2(...) {

expression involving f1();

}

... some other functions, main, etc...



and i'm compiling with

g++ -O file.c -o file


except inline doesn't reduce running time at all! It takes the same amount of time to run whether I include the keyword "inline" or not. I know it should speed up because when I tried to directly insert f1 expression in f2, the program's running time is reduced by about 10 fold.

I'm not sure if I've included all relevant information here... but I would really appreciate it for any possible pointers! Thanks a lot in advance.

Reply With Quote
  #2  
Old April 1st, 2006, 10:44 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Quote:
Originally Posted by welkin
Does anyone know what are some possible reasons that inline doesn't actually inline the functions? (I have already tried google up the usage for inline and I don't see how my program fails to adhere to the rules...) Right now I have a program that looks like..

...

int f1(...);

inline int f1(...) {
some work here, then return some integer.
}


void f2(...) {

expression involving f1();

}

... some other functions, main, etc...



and i'm compiling with

g++ -O file.c -o file


except inline doesn't reduce running time at all! It takes the same amount of time to run whether I include the keyword "inline" or not. I know it should speed up because when I tried to directly insert f1 expression in f2, the program's running time is reduced by about 10 fold.

I'm not sure if I've included all relevant information here... but I would really appreciate it for any possible pointers! Thanks a lot in advance.



The code appears to be fine. As far as timing is concerened, it depends on length of f1.In a way inline is making f1 as a macro.

Reply With Quote
  #3  
Old April 2nd, 2006, 01:30 AM
welkin welkin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 4 welkin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 36 sec
Reputation Power: 0
Quote:
Originally Posted by Cirus
The code appears to be fine. As far as timing is concerened, it depends on length of f1.In a way inline is making f1 as a macro.


Hmm.. thanks. But the weird thing is... the running time's exactly the same when i add/remove the keywords "inline".
and secondly f1 is really short... no more than 4 lines... =\

Reply With Quote
  #4  
Old April 2nd, 2006, 12:02 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Quote:
Originally Posted by welkin
Hmm.. thanks. But the weird thing is... the running time's exactly the same when i add/remove the keywords "inline".
and secondly f1 is really short... no more than 4 lines... =\


Nowdays processors are fast so it may seem unnoticeable time difference after using the two approaches.

Try it on a 166MHz and 32MB or 16 MB RAM , probably then you may find changes.

Also, the different alorithms we have for sorting show time difference depending on hardware we put into use and the kind of input we give.

One thing you can do is to run inline function on a large file and then take time in nanosecs ( because it will be useless to calculate time in milli secs or microsecs as machines are fast).

Reply With Quote
  #5  
Old April 4th, 2006, 10:53 PM
welkin welkin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 4 welkin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 36 sec
Reputation Power: 0
Quote:
Originally Posted by Cirus
Nowdays processors are fast so it may seem unnoticeable time difference after using the two approaches.

Try it on a 166MHz and 32MB or 16 MB RAM , probably then you may find changes.

Also, the different alorithms we have for sorting show time difference depending on hardware we put into use and the kind of input we give.

One thing you can do is to run inline function on a large file and then take time in nanosecs ( because it will be useless to calculate time in milli secs or microsecs as machines are fast).


Ahh, you are probably right.

And also I think inline might've been slowed down because it still needs to create new copies of the variables, right? I ended up using #define and that made it a lot faster. =)

Reply With Quote
  #6  
Old April 5th, 2006, 11:28 PM
welkin welkin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 4 welkin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 36 sec
Reputation Power: 0
New update: After I changed inline functions to pass by reference, the speed is just as fast as that for #define. Thanks to all who helped!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Help on inline; it doesn't work properly


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT