John Harrison said:
Not sure that would give you any improvement. But of course it all depends
on your compiler and STL implementation.
One possible improvement is
BigInt Fibonacci::get_number (uint n_i)
{
fibs_.reserve(n_i + 1); // <<<------------ add this
This improvement is very significant (see below).
John, thank you very much.
const uint cur_size = fibs_.size ();
which will help avoid repeatedly resizing the fibs_ vector.
john
===========================
------------------------------
Windows 2000
CYGWIN_NT-5.0 1.5.5(0.94/3/2)
GNU g++ version 3.3.1 (cygming special)
------------------------------
------ Compilation ------
$ g++ [Optimaze option] -mno-cygwin foo.cpp
-------------------------
Computing Fibonacci[50,000].
Comparative performance.
-----------------------------------------------
| Original | Algorithm with |
Optimization | Algorithm | John Harrison's |
| | improvement |
----------------|-----------------------------|
No optimization | 6.118 | 5.027 |
Optimization O1 | 3.344 | 2.423 |
Optimization O2 | 3.214 | 2.323 |
Optimization O2 | 3.294 | 2.293 |