forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertPerformance.java
More file actions
executable file
·107 lines (87 loc) · 2.68 KB
/
Copy pathInsertPerformance.java
File metadata and controls
executable file
·107 lines (87 loc) · 2.68 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.mxgraph.test;
import java.io.IOException;
import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxICell;
import com.mxgraph.view.mxGraph;
public class InsertPerformance {
public static long testStartTime = 0;
public static void main(String[] args)
{
testStartTime = System.currentTimeMillis();
System.out.println("================");
// Creates graph with model
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
int nodeCount = 10000;
int edgeCount = 2000000;
System.out.println("Start time " + resourceStamp());
graph.getModel().beginUpdate();
//try
{
mxCell[] nodes = new mxCell[nodeCount];
mxCell[] edges = new mxCell[edgeCount];
mxICell dummyGroup = (mxCell) graph.createVertex(parent, null, "I iz a group", 0, 0, 30, 30, null);
for (int i = 0; i < nodeCount; i++)
{
nodes[i] = new mxCell(null, null, null);
nodes[i].setVertex(true);
nodes[i].setConnectable(true);
}
for (int i = 0; i < edgeCount; i++)
{
int r1 = (int) (Math.random() * nodeCount);
int r2 = (int) (Math.random() * nodeCount);
edges[i] = new mxCell(null, null, null);
edges[i].setEdge(true);
nodes[r1].insertEdge(edges[i], true);
nodes[r2].insertEdge(edges[i], false);
}
graph.addCell(dummyGroup, parent, null,null, null);
}
//finally
{
graph.getModel().endUpdate();
}
// try
// {
// Object[] nodes = new Object[nodeCount];
// Object[] edges = new Object[edgeCount];
//
// for (int i = 0; i < nodeCount; i++)
// {
// nodes[i] = graph.insertVertex(parent, null, "N" + i, 0, 0, 30,
// 30);
// }
//
// for (int i = 0; i < edgeCount; i++)
// {
// int r1 = (int) (Math.random() * nodeCount);
// int r2 = (int) (Math.random() * nodeCount);
// edges[i] = graph.insertEdge(parent, null, r1 + "-" + r2,
// nodes[r1], nodes[r2]);
// }
// }
// finally
// {
// graph.getModel().endUpdate();
// }
System.out.println("End update finished " + resourceStamp());
System.out.println("Number of vertices = " + nodeCount);
System.out.println("Number of edges = " + edgeCount);
System.out.print("Paused, press any key to complete");
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Finished");
}
private static String resourceStamp()
{
double time = (System.currentTimeMillis() - testStartTime) / 1000.0;
double mem = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())
/ (1024.0 * 1024.0);
mem = Math.round(mem * 100) / 100.0;
return new String(time + " sec, " + mem + "MB");
}
}