-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix IndexedPointInAreaLocator to reduce calls to synchronized method (#…
…574) Signed-off-by: Martin Davis <[email protected]>
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
modules/core/src/test/java/test/jts/perf/algorithm/IndexedPointInAreaPerfTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package test.jts.perf.algorithm; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
import org.locationtech.jts.algorithm.locate.IndexedPointInAreaLocator; | ||
import org.locationtech.jts.geom.Coordinate; | ||
import org.locationtech.jts.geom.Location; | ||
import org.locationtech.jts.geom.Polygon; | ||
import org.locationtech.jts.util.GeometricShapeFactory; | ||
|
||
import test.jts.perf.PerformanceTestCase; | ||
import test.jts.perf.PerformanceTestRunner; | ||
|
||
public class IndexedPointInAreaPerfTest extends PerformanceTestCase { | ||
public static void main(String args[]) { | ||
PerformanceTestRunner.run(IndexedPointInAreaPerfTest.class); | ||
} | ||
|
||
public IndexedPointInAreaPerfTest(String name) | ||
{ | ||
super(name); | ||
setRunSize(new int[] { 100_000 }); | ||
setRunIterations(1); | ||
} | ||
|
||
List<Coordinate> coords; | ||
Polygon polygon; | ||
|
||
public void startRun(int num) | ||
{ | ||
System.out.println("Running with size " + num); | ||
GeometricShapeFactory factory = new GeometricShapeFactory(); | ||
factory.setSize(100); | ||
polygon = factory.createCircle(); | ||
|
||
coords = new ArrayList<>(); | ||
Random rand = new Random(1324); | ||
for (int i = 0; i < num; i++) { | ||
coords.add(new Coordinate(rand.nextDouble()*100, rand.nextDouble()*100)); | ||
} | ||
} | ||
|
||
public void runParallel() { | ||
for (int i = 0; i < 1000; i++) { | ||
IndexedPointInAreaLocator locator = new IndexedPointInAreaLocator(polygon); | ||
coords.parallelStream().forEach(c -> isInside(locator, c)); | ||
} | ||
} | ||
|
||
private boolean isInside(IndexedPointInAreaLocator locator, Coordinate coord) { | ||
return locator.locate(coord) == Location.INTERIOR; | ||
} | ||
} |