Re: vector.reserve( ) and performance (Was: add_new() for array like push_back() for vector)
>[color=blue]
> I wanted
> * to check what (and how fast) can we compute when using _explicit_[/color]
Fibonacci formula,[color=blue]
> * to create and to test class BigInt,
> * to use this algorithm to compute _all_ Fibonacci numbers 1-n (not only[/color]
Fibonaccci[n])[color=blue]
>[/color]
Another possible optimization, replace
default :
fibs_.push_back (BigInt (get_number (i - 2), get_number (i - 1)));
break;
with
default :
fibs_.push_back (BigInt (fibs_[i - 2], fibs_[i - 1]));
break;
When you are calculating Fib(n), Fib(n-1) and Fib(n-2) must already have
been calculated and stored so this is safe to do. Might save a little time
and can't do any harm.
Actually my intuition is that it will not save any significant time, but
worth a try.
john
>[color=blue]
> I wanted
> * to check what (and how fast) can we compute when using _explicit_[/color]
Fibonacci formula,[color=blue]
> * to create and to test class BigInt,
> * to use this algorithm to compute _all_ Fibonacci numbers 1-n (not only[/color]
Fibonaccci[n])[color=blue]
>[/color]
Another possible optimization, replace
default :
fibs_.push_back (BigInt (get_number (i - 2), get_number (i - 1)));
break;
with
default :
fibs_.push_back (BigInt (fibs_[i - 2], fibs_[i - 1]));
break;
When you are calculating Fib(n), Fib(n-1) and Fib(n-2) must already have
been calculated and stored so this is safe to do. Might save a little time
and can't do any harm.
Actually my intuition is that it will not save any significant time, but
worth a try.
john
Comment