|
-
May 10th, 2012, 12:52 PM
#1
Optimising Code
I'm new to C++, and as an exercise I created a program which calculates pi to n decimal places.
It works, but I want to make it go faster, at the minute it calculates 10,000 digits in around 13 seconds.
I analysed the code, and the two lines taking up the most CPU time are:
Code:
remainder[i] = sum[i] % B[i];
carried[i - 1] = ((sum[i] - remainder[i]) / B[i]) * i;
Each array (remainder, sum, B and carried) contains approximately 15000 elements (more if calculating to more decimal places), each element is a single unsigned integer.
Is there a more efficient way of coding those two lines, or is it just my CPU which is limiting speed?
Thank You,
-Sam
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|