| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
Quote:
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. |
|
#3
|
|||
|
|||
|
Quote:
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... =\ |
|
#4
|
|||
|
|||
|
Quote:
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). |
|
#5
|
|||
|
|||
|
Quote:
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. =) |
|
#6
|
|||
|
|||
|
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!
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Help on inline; it doesn't work properly |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|