Sei sulla pagina 1di 2

(1) In each program, change the n value in same x (e.g.

:n=10,n=100,n=1000,
n=2000,n=5000,n=10000,……),recording it in the following table and compare the different of the
running time.

X=____
NO n Programe 1 Running Programe 2 Running
Time(n) (MilliSecond) Time(n) (MilliSecond)
1 100 ./a.out Please input x and n: 5
Please input x and n:5 100
100 sum=0.833333 ,running
sum=0.833333 ,running time is 0 MS
time is 1 MS
2 1000 ./a.out ./a.out
Please input x and n:5 Please input x and n: 5
1000 100000
sum=0.833333 ,running sum=0.833333 ,running
time is 10 MS time is 1 MS
3 5000 ./a.out ./a.out
Please input x and n:5 Please input x and n: 5
5000\ 500000
sum=0.833333 ,running sum=0.833333 ,running
time is 79 MS time is 5 MS
4 10000 ./a.out ./a.out
Please input x and n:5 Please input x and n: 5
10000 1000000
sum=0.833333 ,running sum=0.833333 ,running
time is 273 MS time is 11 MS
5 50000 ./a.out ./a.out
Please input x and n:5 Please input x and n: 5
50000 5000000
sum=0.833333 ,running sum=0.833333 ,running
time is 6120 MS time is 24 MS

(2) In each program, remove the sentence of “get the system current time”, add a counter in the loop
body, recording the number of the loop execution. Change the n value in same x (e.g.:
n=10,n=100,n=1000, n=2000,n=5000,n=10000,……),recording the loop running times in a table
which design by yourself

No n
1 n=10 ./a.out
Please input x and n: 5
10
10 0.000000
2 N=100 ./a.out
Please input x and n: 5
100
100 0.000000
3 N=1000 ./a.out
Please input x and n: 5
1000
1000 0.000000
4 N=2000 ./a.out
Please input x and n: 5
2000
2000 0.000000

(END)

Potrebbero piacerti anche