Re: C++ Application Performing Unacceptably



 DEVELOP > c-Plus-Plus > Re: C++ Application Performing Unacceptably

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1
Topic: DEVELOP > c-Plus-Plus
User: "James Aguilar"
Date: 16 Jan 2005 03:36:57 PM
Object: Re: C++ Application Performing Unacceptably
Here's the problem:
--- CODE ---
i=j=0
while i<1000000:
while j<50000:
n=ints[i%len(ints)] + ints[j%len(ints)] #Add
n=ints[j%len(ints)] - ints[i%len(ints)] #Subtract
n=ints[i%len(ints)] * ints[j%len(ints)] #Multiply
n=ints[j%len(ints)] / ints[i%len(ints)] #Divide
n=ints[i%len(ints)]**exp[j%len(exp)] #Exponents
n=abs(cmath.sqrt(pos[i%len(pos)])) #Square roots
n=abs(cmath.sin(ints[j%len(ints)])) #Sines
j=j+1 #Iterate
i=i+1 #Iterate
--- CODE ---
You never reset J, so this program will only do the tests 50000 times, then
it will find false 9999999 more times, which is fast.
In your c++ version, the loop counter is reset every time.
--- CODE ---
for(int i=0; i<1000000; i++) {
for(int j=0; j<50000; j++) { //<--- loop counter resets
--- CODE ---
That is why it happened this way. Your C++ version is trying to do 9999999
times as much work.
JFA
.

 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER