forked from liujiboy/Java_Course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumTest.java
More file actions
38 lines (34 loc) · 770 Bytes
/
SumTest.java
File metadata and controls
38 lines (34 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package cqu;
public class SumTest {
public static void main(String[] args) {
SumThread threads[]=new SumThread[10];
long start=System.nanoTime();
for(int i=0;i<threads.length;i++)
{
threads[i]=new SumThread(i*10000+1,(i+1)*10000);
threads[i].start();
}
int result=0;
for(int i=0;i<threads.length;i++)
{
try {
threads[i].join();
} catch (InterruptedException e) {
e.printStackTrace();
}
result+=threads[i].getResult();
}
System.out.println(result);
long end=System.nanoTime();
System.out.println(end-start);
start=System.nanoTime();
result=0;
for(int i=1;i<=100000;i++)
{
result+=Math.sqrt(Math.sqrt(i));
}
System.out.println(result);
end=System.nanoTime();
System.out.println(end-start);
}
}