-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...arks/src/main/scala/com.daodecode.scalax.benchmarks/IterableLikeExtensionsBenchmark.scala
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,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() | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
benchmarks/src/main/scala/com.daodecode.scalax.benchmarks/SeqExtensionsBenchmark.scala
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,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) | ||
} | ||
|
||
} |
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
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