> So I did the following:
> Right click on the project -> Properties -> C/C++ -> Build Variables -> LD_LIBRARY_PATH
> and included the path the in the environment variable.
I've no familiarity at all with the Eclipse IDE.
Try setting the LD_LIBRARY_PATH environment variable in the shell, and then starting the Eclipse IDE from the shell.
For example, in the C shell setenv LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/bin/boostCppLib/lib
(Adding this line to .cshrc in your home directory would be convenient).
That seems a strange location to install boost. The bin directories are supposed to be for executable (binary) files. In my system boost is in /usr/include/boost, so I would have :
#include </boost/timer/timer.hpp>
You could just move the files there, IIRC that's what I did in my install.
And you seemed to have lumped all the libraries in there too. I installed boost into /opt/boost1_61 ; the libraries are in the libs directory under that.
I am finally able to use the boost library timer :) yuhu!!. However I am surprised to see that, considering the processor time, the iterative code executes slower than the recursive code (I was expecting the other way around). this is my code:
> Iterative code should be always executed faster than recursive code
Not necessarily. With modern compilers (particularly clang++), often simple tail-recursive code executes a wee bit faster than iterative code. However, when the recursive code is slower (for instance, if non-trivial destruction of local objects are involved), it is very much slower.
Incidentally, there is no recursive code in your program, the second version too is iterative; the difference being that a function is called during each iteration.
The auto_cpu_timer prints timer statistics when the object is destroyed; so the first timer is printing the time taken from the time it was constructed till the end of main. (Which is why the output with the tag boost_it appears after the one with the tag boost_rec.)
Both these pieces of code (the two versions computing the approximate factorial) should take roughly the same amount of time.
the second version too is iterative; the difference being that a function is called during each iteration
How could I implement recursive code for the second version?
My main target is to demonstrate that recursive code normally executes slower than iterative code.
I thought that putting a function would make the code more recursive :S