By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

Performance/memory problems with arrays?

P: n/a
I am working on some financial calculators and although I succeeded to
created the required formulas I am not sure about the following.To give an
example: when somebody puts a capital on the bank with a yearly interest of
x % , the final capital after, say, 30 years can easily be calculated.
Since I want to be able to show the capital created after every year I
prefer to do it with a loop, something like
for($x= 1; $x < 30; $x++){
$capital = $capital*(1 + $interest /100)
} .
Another reason for such a loop is that the visitor could tell that he want
to withdraw some capital in the so-manieth year
Now let's say the visitor of the page can do a "quick scan" (just showing
the final amount) and request a table with all the yearly amounts
afterwards. In this case I will either have to store all the yearly capital
values into a an array and register that array to a session, or I will need
to do the whole loop again but this time something like
$capital = $capital*(1+ $interest/100);
echo "<tr><td>$capital</td></tr>";
Although the formulas I "translated" from several excel sheets work fine, I
would like to know if storing such arrays could have negative consequences
for performance or memory on the server
Alternative suggestions, of course are also welcome. I tried to find similar
scripts on Google but I wasn't very successfull, probably because I am not
very familiar with the English financial terms

Thanks for any help.

Martien.

Feb 9 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Martien van Wanrooij wrote:
I am working on some financial calculators and although I succeeded to
created the required formulas I am not sure about the following.To give
an example: when somebody puts a capital on the bank with a yearly
interest of x % , the final capital after, say, 30 years can easily be
calculated. Since I want to be able to show the capital created after
every year I prefer to do it with a loop, something like
for($x= 1; $x < 30; $x++){
$capital = $capital*(1 + $interest /100)
} .
Another reason for such a loop is that the visitor could tell that he
want to withdraw some capital in the so-manieth year
Now let's say the visitor of the page can do a "quick scan" (just
showing the final amount) and request a table with all the yearly
amounts afterwards. In this case I will either have to store all the
yearly capital values into a an array and register that array to a
session, or I will need to do the whole loop again but this time
something like
$capital = $capital*(1+ $interest/100);
echo "<tr><td>$capital</td></tr>";
Although the formulas I "translated" from several excel sheets work
fine, I would like to know if storing such arrays could have negative
consequences for performance or memory on the server
Alternative suggestions, of course are also welcome. I tried to find
similar scripts on Google but I wasn't very successfull, probably
because I am not very familiar with the English financial terms

Thanks for any help.

Martien.
Martien,

Programming is all about tradeoffs. Often time the tradeoff is between
memory and cpu utilization.

Would storing arrays have negative consequences? Sure. But so would
calculating the figures every time.

Which is better? It's impossible to tell. It all depends on your
server, your users (both number and frequency) and probably a dozen
other things.

You need to figure out how much data you're talking about and how often
it's being requested. That will help you determine which is the better
way to go.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 10 '07 #2

P: n/a

"Jerry Stuckle" <js*******@attglobal.netschreef in bericht
news:Eb******************************@comcast.com. ..
You need to figure out how much data you're talking about and how often
it's being requested. That will help you determine which is the better
way to go.
Thanks Jerry, the problem is that I am not very "handy" at estimating such
performance issues, maybe it is just a matter of experience. Not that I am
extremely worried that my mortgage calculation will be visited at the same
time by so many visitors that it would make crash my hosting provider's
server but I want to take in mind such considerations from the very
beginning. Anyway your reaction makes me think that I shouldn't be too
worried about the script I am writing, thanks agein :)

Feb 10 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.