Skip to content

Commit 655fa18

Browse files
author
Peter
committed
more unit performance tests
1 parent 20a5c68 commit 655fa18

File tree

2 files changed

+58
-17
lines changed

2 files changed

+58
-17
lines changed

core/src/main/java/com/graphhopper/routing/util/LevelEdgeFilter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.graphhopper.storage.LevelGraph;
2121
import com.graphhopper.util.EdgeIteratorState;
2222
import com.graphhopper.util.EdgeSkipIterState;
23-
import com.graphhopper.util.EdgeSkipIterator;
2423

2524
/**
2625
* Only certain nodes are accepted and therefor the others are ignored.

tools/src/main/java/com/graphhopper/tools/Measurement.java

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@
2323
import com.graphhopper.coll.GHBitSet;
2424
import com.graphhopper.coll.GHBitSetImpl;
2525
import com.graphhopper.routing.util.*;
26+
import com.graphhopper.storage.*;
2627
import com.graphhopper.storage.index.LocationIndex;
27-
import com.graphhopper.storage.Graph;
28-
import com.graphhopper.storage.GraphStorage;
29-
import com.graphhopper.storage.NodeAccess;
30-
import com.graphhopper.storage.RAMDirectory;
3128
import com.graphhopper.util.*;
3229
import com.graphhopper.util.shapes.BBox;
3330

@@ -116,12 +113,13 @@ void start( CmdArgs args )
116113
throw new IllegalStateException("Graph has to be unprepared but wasn't!");
117114

118115
String vehicleStr = args.get("graph.flagEncoders", "");
116+
FlagEncoder encoder = hopper.getEncodingManager().getEncoder(vehicleStr);
119117
StopWatch sw = new StopWatch().start();
120118
try
121119
{
122120
maxNode = g.getNodes();
123121
GHBitSet allowedEdges = printGraphDetails(g, vehicleStr);
124-
printMiscUnitPerfTests(hopper, vehicleStr, count * 100, allowedEdges);
122+
printMiscUnitPerfTests(false, g, encoder, count * 100, allowedEdges);
125123
printLocationIndexQuery(g, hopper.getLocationIndex(), count);
126124

127125
// Route via dijkstrabi. Normal routing takes a lot of time => smaller query number than CH
@@ -134,6 +132,10 @@ void start( CmdArgs args )
134132
// route via CH. do preparation before
135133
hopper.setCHEnable(true);
136134
hopper.doPostProcessing();
135+
136+
LevelGraph lg = (LevelGraph) g;
137+
fillAllowedEdges(lg.getAllEdges(), allowedEdges);
138+
printMiscUnitPerfTests(true, lg, encoder, count * 100, allowedEdges);
137139
printTimeOfRouteQuery(hopper, count, "routingCH", vehicleStr, true);
138140
printTimeOfRouteQuery(hopper, count, "routingCH_no_instr", vehicleStr, false);
139141
logger.info("store into " + propLocation);
@@ -161,6 +163,15 @@ void start( CmdArgs args )
161163
}
162164
}
163165

166+
void fillAllowedEdges( AllEdgesIterator iter, GHBitSet bs )
167+
{
168+
bs.clear();
169+
while (iter.next())
170+
{
171+
bs.add(iter.getEdge());
172+
}
173+
}
174+
164175
private GHBitSet printGraphDetails( GraphStorage g, String vehicleStr )
165176
{
166177
// graph size (edge, node and storage size)
@@ -172,10 +183,7 @@ private GHBitSet printGraphDetails( GraphStorage g, String vehicleStr )
172183
AllEdgesIterator iter = g.getAllEdges();
173184
final int maxEdgesId = g.getAllEdges().getCount();
174185
final GHBitSet allowedEdges = new GHBitSetImpl(maxEdgesId);
175-
while (iter.next())
176-
{
177-
allowedEdges.add(iter.getEdge());
178-
}
186+
fillAllowedEdges(iter, allowedEdges);
179187
put("graph.valid_edges", allowedEdges.getCardinality());
180188
return allowedEdges;
181189
}
@@ -205,13 +213,47 @@ public int doCalc( boolean warmup, int run )
205213
print("location2id", miniPerf);
206214
}
207215

208-
private void printMiscUnitPerfTests( final GraphHopper hopper, String vehicle, int count,
209-
final GHBitSet allowedEdges )
216+
private void printMiscUnitPerfTests( boolean isCH, final Graph graph, final FlagEncoder encoder,
217+
int count, final GHBitSet allowedEdges )
210218
{
211219
final Random rand = new Random(seed);
212-
final GraphStorage graph = hopper.getGraph();
220+
String description = "";
221+
if (isCH)
222+
{
223+
description = "CH";
224+
LevelGraph lg = (LevelGraph) graph;
225+
final EdgeSkipExplorer chExplorer = lg.createEdgeExplorer(
226+
new LevelEdgeFilter((LevelGraph) graph));
227+
MiniPerfTest miniPerf = new MiniPerfTest()
228+
{
229+
@Override
230+
public int doCalc( boolean warmup, int run )
231+
{
232+
int nodeId = rand.nextInt(maxNode);
233+
return GHUtility.count(chExplorer.setBaseNode(nodeId));
234+
}
235+
}.setIterations(count).start();
236+
print("unit_testsCH.level_edge_state_next", miniPerf);
237+
238+
final EdgeSkipExplorer chExplorer2 = lg.createEdgeExplorer();
239+
miniPerf = new MiniPerfTest()
240+
{
241+
@Override
242+
public int doCalc( boolean warmup, int run )
243+
{
244+
int nodeId = rand.nextInt(maxNode);
245+
EdgeSkipIterator iter = chExplorer2.setBaseNode(nodeId);
246+
while (iter.next())
247+
{
248+
if (iter.isShortcut())
249+
nodeId += (int) iter.getWeight();
250+
}
251+
return nodeId;
252+
}
253+
}.setIterations(count).start();
254+
print("unit_testsCH.get_weight", miniPerf);
255+
}
213256

214-
FlagEncoder encoder = hopper.getEncodingManager().getEncoder(vehicle);
215257
EdgeFilter outFilter = new DefaultEdgeFilter(encoder, false, true);
216258
final EdgeExplorer outExplorer = graph.createEdgeExplorer(outFilter);
217259
MiniPerfTest miniPerf = new MiniPerfTest()
@@ -223,7 +265,7 @@ public int doCalc( boolean warmup, int run )
223265
return GHUtility.count(outExplorer.setBaseNode(nodeId));
224266
}
225267
}.setIterations(count).start();
226-
print("unit_tests.out_edge_state_next", miniPerf);
268+
print("unit_tests" + description + ".out_edge_state_next", miniPerf);
227269

228270
final EdgeExplorer allExplorer = graph.createEdgeExplorer();
229271
miniPerf = new MiniPerfTest()
@@ -235,7 +277,7 @@ public int doCalc( boolean warmup, int run )
235277
return GHUtility.count(allExplorer.setBaseNode(nodeId));
236278
}
237279
}.setIterations(count).start();
238-
print("unit_tests.all_edge_state_next", miniPerf);
280+
print("unit_tests" + description + ".all_edge_state_next", miniPerf);
239281

240282
final int maxEdgesId = graph.getAllEdges().getCount();
241283
miniPerf = new MiniPerfTest()
@@ -251,7 +293,7 @@ public int doCalc( boolean warmup, int run )
251293
}
252294
}
253295
}.setIterations(count).start();
254-
print("unit_tests.get_edge_state", miniPerf);
296+
print("unit_tests" + description + ".get_edge_state", miniPerf);
255297
}
256298

257299
private void printTimeOfRouteQuery( final GraphHopper hopper, int count, String prefix,

0 commit comments

Comments
 (0)