Skip to content

Commit

Permalink
WIP add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
jozic committed Jan 18, 2018
1 parent 53e4c58 commit d50a8f5
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.daodecode.scalax.benchmarks

import org.openjdk.jmh.annotations._
import com.daodecode.scalax.collection.extensions._

import scala.collection.immutable

@State(Scope.Benchmark)
@BenchmarkMode(Array(Mode.Throughput))
class IterableLikeExtensionsBenchmark {

@Param(Array("10", "100", "1000", "10000", "100000", "1000000"))
var size: Int = _

var iterable: Iterable[(Int, String)] = _

@Setup
def prepare: Unit = {
iterable = Iterable((0 to size).map(i => i -> i.toString): _*)
}

// @Benchmark
// def identityMap: Unit = {
// iterable.map(identity)
// }

@Benchmark
def mapAndToMapBenchmark: Unit = {
iterable.map(identity).toMap
}

@Benchmark
def mapAndToMapBenchmark2: Unit = {
iterable.map(identity).toMap
}

@Benchmark
def mapToMapBenchmark: Unit = {
iterable.mapToMap(identity)
}

@Benchmark
def mapToMapInlinedBenchmark: Unit = {
val b = immutable.Map.newBuilder[Int, String]
for (a <- iterable)
b += identity(a)
b.result()
}

@Benchmark
def mapToMapInlinedBenchmark2: Unit = {
val b = immutable.Map.newBuilder[Int, String]
for (a <- iterable)
b += identity(a)
b.result()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.daodecode.scalax.benchmarks

import org.openjdk.jmh.annotations.{Benchmark, Scope, State}
import com.daodecode.scalax.collection.extensions._

case class Person(fName: String, lName: String, age: Int)


@State(Scope.Benchmark)
class SeqExtensionsBenchmark {


val eugeneP = Person("Eugene", "Platonov", 27)
val xeniya = Person("Xeniya", "Skrypnyk", 27)
val eugeneM = Person("Eugene", "Medvediev", 31)
val vasiliy = Person("Vasiliy", "Platonov", 2)

val people = Seq(eugeneP, xeniya, eugeneM, vasiliy)

@Benchmark
def testDistinctBySimple: Unit = {
people.distinctBy(_.fName)
}

}
9 changes: 9 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ initialCommands in console :=
|import com.daodecode.scalax._
|""".stripMargin


//benchmarks

lazy val `scalax-collection` = project.in(file("."))

lazy val benchmarks =
project
.dependsOn(`scalax-collection`)
.enablePlugins(JmhPlugin)
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.6.2")

addSbtPlugin("com.github.tkawachi" % "sbt-doctest" % "0.7.0")

addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.2")

0 comments on commit d50a8f5

Please sign in to comment.