Moin Moin!
Danke für eure Antworten!!
Ihr habt recht, der von mir kopierte Code-Teil ist nicht das Problem. Anbei der komplette Code und nachfolgend die Zeiten. Der Flaschenhals ist demnach das setText(str) in die JEditorPane in Zeile 81. Gibt's da etwas das ich optiemieren könnte?
Java Code:
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
| package view.dialog;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JFrame;
import model.LibraryTableModel;
import model.Paper;
public class AuthorStatisticsDialog extends HTMLDialog {
private LibraryTableModel model;
long time_1, time_2, time_3, time_4, time_5, time_6, time_7, time_8;
public AuthorStatisticsDialog(JFrame frame, String title, boolean modal, LibraryTableModel model) {
super(frame, title, modal);
time_1 = System.nanoTime();
this.model = model;
createStatistics();
time_8 = System.nanoTime();
System.out.println("Duration 4 = " + (time_4 - time_1));
System.out.println("Duration 5 = " + (time_5 - time_1));
System.out.println("Duration 6 = " + (time_6 - time_1));
System.out.println("Duration 7 = " + (time_7 - time_1));
System.out.println("Duration 8 = " + (time_8 - time_1));
}
private void createStatistics() {
StringBuilder sb = new StringBuilder();
sb.append("<html><head><style type=\"text/css\">table { font-size: 10px; font-family: sans-serif; } th { text-align: left; background-color: #cccccc; } </style></head><body>");
sb.append("<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\">");
sb.append("<thead><tr><th>Author</th><th>Anzahl</th></tr></thead>");
sb.append("<tbody>");
int n = model.getRowCount();
time_2 = System.nanoTime();
System.out.println("n = " + n);
ArrayList<Paper> papers = model.getPapers();
HashMap<String, Integer> stats = new HashMap<String, Integer>();
time_3 = System.nanoTime();
for (int i = 0; i < n; i++) {
String authors = papers.get(i).getAuthorList();
String[] array = authors.split(",");
for (int j = 0; j < array.length; j++) {
String author = array[j].trim().toUpperCase();
int count = stats.containsKey(author) ? stats.get(author) : 0;
stats.put(author, count + 1);
}
}
System.out.println("entries = " + stats.size());
time_4 = System.nanoTime();
for (Map.Entry e : stats.entrySet()) {
sb.append("<tr><td>" + e.getKey() + "</td><td>" + e.getValue() + "</td></tr>");
}
time_5 = System.nanoTime();
sb.append("</tbody></table></body></body></html>");
String str = sb.toString();
time_6 = System.nanoTime();
ep.setText(str);
time_7 = System.nanoTime();
ep.setCaretPosition(0);
}
} |
########################################
Hier die Zeiten:
Duration 4 = 23465678
Duration 5 = 31601539
Duration 6 = 31650569
Duration 7 = 6310137191
Duration 8 = 6310223376
########################################
Java Code:
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
| package view.dialog;
import java.awt.Dimension;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import org.jdesktop.swingx.JXEditorPane;
public class HTMLDialog extends JDialog {
protected JScrollPane sp;
protected JXEditorPane ep;
public HTMLDialog(JFrame frame, String title, boolean modal) {
super(frame, title, modal);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
ep = new JXEditorPane("text/html", "");
ep.setEditable(false);
ep.setPreferredSize(new Dimension(640, 480));
sp = new JScrollPane(ep);
add(sp);
pack();
setLocationRelativeTo(null);
}
} |