Skip to content

Commit

Permalink
Switch to caliper benchmarks for geometry sequence ops
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeah committed Feb 12, 2015
1 parent 7602564 commit a43c275
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 44 deletions.
Expand Up @@ -18,8 +18,6 @@ package geotrellis.vector.benchmark

import geotrellis.vector.check.jts.Generators

import geotrellis.vector.MultiLine

import org.scalacheck.{Prop,Test,Gen,Arbitrary}

import com.vividsolutions.jts.geom._
Expand Down Expand Up @@ -160,45 +158,6 @@ object GeneratorBenchmarks {
println(s"Average for line string Seq point intersection: ${times/duration.toDouble}")
}

def do3() = {
val results =
benchmarkArb((ml:MultiLineString,p:Point) => countMulti(ml))({ (ml: MultiLineString,p:Point) =>
MultiLine(ml).intersection()
})

val (times,duration) =
results
.map { case (count,times,duration) => (count*times,duration) }
.reduce { (t1,t2) => (t1._1+t2._1,t1._2+t2._2) }
println(s"Average for MultiLine intersection: ${times/duration.toDouble}")
}

def do4() = {
val results =
benchmarkArb((ml:MultiLineString,p:Point) => countMulti(ml))({ (ml: MultiLineString,p:Point) =>
MultiLine(ml).difference()
})

val (times,duration) =
results
.map { case (count,times,duration) => (count*times,duration) }
.reduce { (t1,t2) => (t1._1+t2._1,t1._2+t2._2) }
println(s"Average for MultiLine difference: ${times/duration.toDouble}")
}

def do5() = {
val results =
benchmarkArb((ml:MultiLineString,p:Point) => countMulti(ml))({ (ml: MultiLineString,p:Point) =>
MultiLine(ml).symDifference()
})

val (times,duration) =
results
.map { case (count,times,duration) => (count*times,duration) }
.reduce { (t1,t2) => (t1._1+t2._1,t1._2+t2._2) }
println(s"Average for MultiLine symDifference: ${times/duration.toDouble}")
}

lazy val genListLineString:Gen[List[LineString]] =
Gen.choose(1,20).flatMap(Gen.containerOfN[List,LineString](_,genLineString))
lazy val arbListLineString:Arbitrary[List[LineString]] =
Expand All @@ -207,8 +166,5 @@ object GeneratorBenchmarks {
def main(args:Array[String]):Unit = {
do1()
do2()
do3()
do4()
do5()
}
}
@@ -0,0 +1,40 @@
package geotrellis.vector.benchmark

import geotrellis.vector._

import geotrellis.vector.check.jts.Generators

import org.scalacheck.{Test,Gen}

object GeometrySequenceOps extends BenchmarkRunner(classOf[GeometrySequenceOps])
class GeometrySequenceOps extends FeatureBenchmark {

var ml: MultiLine = null

override def setUp() {
val params = Test.Parameters.default
val genPrms = new Gen.Parameters.Default { override val rng = params.rng }

ml = null
while (ml == null) {
Generators.genMultiLineString(genPrms) match {
case None =>
case Some(value) =>
ml = MultiLine(value)
}
}
}

def timeMultiLineUnion(reps: Int) = run(reps)(multiLineUnion)
def multiLineUnion = ml.union

def timeMultiLineIntersection(reps: Int) = run(reps)(multiLineIntersection)
def multiLineIntersection = ml.intersection

def timeMultiLineDifference(reps: Int) = run(reps)(multiLineDifference)
def multiLineDifference = ml.difference

def timeMultiLineSymDifference(reps: Int) = run(reps)(multiLineSymDifference)
def multiLineSymDifference = ml.symDifference
}

0 comments on commit a43c275

Please sign in to comment.