代码大概是这样的 就是构造一个轨道系统,其中createAthlete方法就是new一个对象,然后addo就是add到一个arraylist里
在读1000条数据以内时候就几毫秒构造一条,在读到七八千条数据的时候就特别特别慢了。想知道要怎么加快后面的处理速度呢?(一共要处理50w条数据)
(这是几千条后打印的时间:
构造Athlete ::= 时间:777ms
构造Athlete ::= 时间:728ms
构造Athlete ::= 时间:444ms
构造Athlete ::= 时间:764ms
构造Athlete ::= 时间:703ms
构造Athlete ::= 时间:730ms
构造Athlete ::= 时间:426ms
构造Athlete ::= 时间:797ms
构造Athlete ::= 时间:951ms
构造Athlete ::= 时间:266ms
构造Athlete ::= 时间:1853ms
构造Athlete ::= 时间:715ms
)
for(int k=0;k<arrayList.size();k++){
long startTime1 = System.currentTimeMillis();
line=arrayList.get(k);
String pattern = "(\\w+)(\\W+)(.*)";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(line);
if(m.find()) {
if(m.group(1).equals("Game")) {
cir.addCenter(m.group(3));
}
else if(m.group(1).equals("Athlete")) {
String line1=m.group(3);
String pattern1 = "(\\w+),(\\d+),(\\w+),(\\d+),(\\d+.\\d+)>";
Pattern r1 = Pattern.compile(pattern1);
Matcher m1 = r1.matcher(line1);
if(m1.find()) {
Athlete athlete=physicalObject.createAthlete(m1.group(1),Integer.parseInt(m1.group(2)),m1.group(3),Integer.parseInt(m1.group(4)),Double.parseDouble(m1.group(5)));
cir.addo(athlete);
}
}
else {
int a=Integer.parseInt(m.group(3).trim());
for(int i=0;i<a;i++) {
cir.addTrack();
}
}
}
long endTime1 = System.currentTimeMillis();
System.out.println("构造"+line+"时间:" + (endTime1 - startTime1) + "ms");
}
}